Unsolved How to set the color of the selected QTreeWidgetItem?
-
How to set the color of the selected QTreeWidgetItem?
the default selected background color of QTreeWidgetItem is dark-blue, i want to remove this background color and just set a red rectangle for the selected item.
thank you! -
Use setdata function and pass the role as background role or text role
-
BackgroundRole? i think this is not what i need.
cause i just want to change the background color of the Selected WidgetItem. or remove the background color of the Selected WidgetItem -
@opengpu2
Hi,I would suggest looking into StyleSheets
with them its easy to accomplish what you want in your case:
the default selected background color of QTreeWidgetItem is dark-blue, i want to remove this background color and just set a red rectangle for the selected item.
thank you !listWidget->setStyleSheet("QListView::item:selected {background : transparent; border: solid 2px red;}");
-
thank you very much!
-
just noticed a typo in my code
background:
ought to be
background-color:
but you should notice that yourself when you read through the docu :)
-
ok i got it, thanks very much
-
@J.Hilk
i tried, but it is white background...and the clicked coloum background is grey... -
-
QListView { show-decoration-selected: 1; } QListView::item:selected { border: 1px solid red; color: black; } QListView::item:selected:!active { background: transparent; } QListView::item:selected:active { background: transparent; } QListView::item:hover { border: 1px solid #FF8888; }
If you need more subcontrols, add style. Or vice versa ...
-
thank you very much
it does work!
but my problem is more complicated.
i have 2 column in a QTreeWidget, the 1st column is text, the 2nd column i set different color by setBackgroundColor for different rows.
and the problem is the default selected item is all blue...
now i just want the selected item has a border, and the 1st column has default white background and black text, the 2nd column still has its own background color which i set for different rows. -
anyone can help? thx
-
You can always disable the default focus of your listwidget
widget->setFocusPolicy(Qt::NoFocus);
And "create your own 'focusHanlder' "
connect(widget, &QListWidget::clicked, [=](QModelIndex index){ //Do Custom Stuff with clicked item });