Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView disable highlight on select, delegate not working
Qt 6.12 LTS is out! See what's new in the release blog

QTableView disable highlight on select, delegate not working

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hello,

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

    There is picture with problem(second item):
    !http://www.sdilej.eu/pics/132f736eaa2ec37dfb5bc806d664752e.PNG(Problem)!

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

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

    };@

    Thanks for reply and help!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved