qt在tableview中绘制图片
Posted tianmochou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了qt在tableview中绘制图片相关的知识,希望对你有一定的参考价值。
void ItemModelDeletage::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem viewOption(option);
initStyleOption(&viewOption, index);
if (option.state.testFlag(QStyle::State_HasFocus))
viewOption.state = viewOption.state ^ QStyle::State_HasFocus;
ItemModelDeletage::paint(painter, viewOption, index);
if(index.column() == AllowTradeTime::Operator)
{
QStyleOptionButton buttonStyle;
buttonStyle.rect = option.rect.adjusted(0, 0, 0, 0);
buttonStyle.text = "X";
buttonStyle.state = QStyle::State_Enabled;
QPushButton button;
buttonStyle.initFrom(&button);
button.setFlat(true);
button.setStyleSheet("QPushButton{ border-image:url(res/skin/default/images/dockwidget/dock_close.png) no-repeat;}");
//QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonStyle, painter);
//painter->drawText(option.rect,Qt::AlignJustify | Qt::AlignVCenter | Qt::AlignHCenter,"X");
QImage image;
bool re= image.load("res\skins\default\images\dockwidget\time_delete.png");
int sx =-45;
int sy = -10;
int sw = 80;
int sh = 35;
painter->drawImage(option.rect.x(),option.rect.y(),image,sx, sy,sw,sh,Qt::AutoColor);
}
}
以上是关于qt在tableview中绘制图片的主要内容,如果未能解决你的问题,请参考以下文章