QTableView disable highlight on select, delegate not working

  • Hello,

    I have some trouble with delegate which will disable highlight on item select in QTableView.

    There is picture with problem(second item):

    Following code for delegate:
    @class BGDelegate : public QStyledItemDelegate
    explicit BGDelegate(QObject* parent = 0) : QStyledItemDelegate(parent)

    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
        QVariant bg = index.data(Qt::BackgroundRole);
            painter->fillRect(option.rect, bg.value<QBrush>());
        QStyledItemDelegate::paint(painter, option, index);
        if(option.state & QStyle::State_Selected)
           QPen pen(Qt::black, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
           int w = pen.width() / 2;
           painter->drawRect(option.rect.adjusted(w, w, -w, -w));


    Thanks for reply and help!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.