[SOLVED]QTreeWidget setStyleSheet problem
-
I want to set the selected QTreeWidgetItem to a custom color, using the code below:
setStyleSheet("QTreeWidget::item::selected{background-color: rgb(50, 50, 50)}");
but it does not work very well: there is some other color on the left part of the QTreeWidgetItem.
Is there any way to solve this? -
Hi
A QTreeWidget will show an arrow for items with children. to the left.
Is it that area you area talking about ?Its not considered part of the item and will have the color for
background-color for the whole TreeWidget.If you do not need a tree view, then maybe just use a listwidget where the item
will take up all row. ? -
@mrjj Yes, it is the area to show an arrow for items with children.
-
@mrjj It is used to show the tree of scene, so I have to use the QTreeVidget.
-
@tony_tang
That area can be styled with QTreeView::branch
have a look at
https://forum.qt.io/topic/8034/changing-the-color-of-qtreeview-s-branches/2 -
@mrjj
OK, I take a try, thank you very much. -
@tony_tang
I solved the problem using this method:QPalette pal = palette();
pal.setColor(QPalette::ColorRole::Highlight, QColor(50, 50, 50));
setPalette(pal); -
@tony_tang said:
Super!
Thank you for reporting back.