QTreeView disable highlighting on a row hover

1.7k views Asked by At

I don't want rows to be highlighted on mouse hover. How to disable this highlighting?

enter image description here

Either remove highlighting at all or change it's color: both solutions are fine.

2

There are 2 answers

4
Vahagn Avagyan On BEST ANSWER
tView->setStyleSheet("QTreeView::item:hover{background-color:rgb(255,255,255);}");
0
Arnaud On

You can do it the Delegate way:

#include <QStyledItemDelegate>

class NoHighlightDelegate:public QStyledItemDelegate{
public:
    void initStyleOption(QStyleOptionViewItem*option,const QModelIndex&viewIndex)const override{
        QStyledItemDelegate::initStyleOption(option,viewIndex);
        option->state&=~QStyle::State_MouseOver;}
};

Then set this Delegate to your QTreeView:

//QTreeView*view;
auto*delegate=new NoHighlightDelegate();
delegate->setParent(view);
view->setItemDelegate(delegate);

And you will not get into the hidden selected line problem.