How to set the color of the selected QTreeWidgetItem?
-
wrote on 20 Feb 2017, 05:17 last edited by
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 -
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!@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;}");
-
wrote on 20 Feb 2017, 06:08 last edited by
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 :)
-
wrote on 20 Feb 2017, 06:17 last edited by
ok i got it, thanks 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 :)
-
@J.Hilk
i tried, but it is white background...and the clicked coloum background is grey...wrote on 22 Feb 2017, 12:23 last edited by Devopia53QListView { 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 ...
-
wrote on 23 Feb 2017, 03:49 last edited by
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. -
wrote on 24 Feb 2017, 09:14 last edited by
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 });
12/13