Nikolai Shalakin
Nikolai Shalakin

Reputation: 1484

QTreeView disable highlighting on a row hover

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.

Upvotes: 1

Views: 1959

Answers (2)

Arnaud
Arnaud

Reputation: 3741

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.

Upvotes: 2

Vahagn Avagyan
Vahagn Avagyan

Reputation: 776

tView->setStyleSheet("QTreeView::item:hover{background-color:rgb(255,255,255);}");

Upvotes: 1

Related Questions