码迷,mamicode.com
首页 > 其他好文 > 详细

qt在tableview中绘制图片

时间:2018-07-03 16:45:40      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:ons   png   ima   res   ini   draw   drawtext   no-repeat   styles   

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中绘制图片

标签:ons   png   ima   res   ini   draw   drawtext   no-repeat   styles   

原文地址:https://www.cnblogs.com/tianmochou/p/9259022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!