Adding a QTreeWidget item border
Solved
General and Desktop
-
I would like to achieve an item border similar to what is found in Qt Designer:
I tried the following:
QTreeWidget { background: rgb(250,250,225); alternate-background-color: rgb(250,250,200); } QTreeWidget::item { border-bottom: 1px solid rgb(216, 216, 216); } QTreeWidget::item:selected { background: rgb(220,240,250); border-bottom: 1px solid rgb(216, 216, 216); }
and:
myTreeWidget.setAlternatingRowColors(True) myApplication.setStyleSheet(myStyleSheet)
However, this is the result:
The problem is that the border lines do not go all the way to the left.
Interestingly, the border on the selected item is drawn as expected.
Any help would be greatly appreciated. -
Hi and welcome to devnet,
Unless I am mistaken, the answer lies in the branch part of the QTreeView styling example.
-
@SGaist Thank you for your help.
I was able to achieve the desired effect by adding the following:QTreeView::branch{ border-bottom: 1px solid rgb(210, 210, 210); }
However, annoyingly, this will remove the arrows from the tree. These can be added via:
QTreeView::branch:closed:has-children { border-image: none; image: url(C:/Users/Carlos/Desktop/branch-closed.png); } QTreeView::branch:open:has-children { border-image: none; image: url(C:/Users/Carlos/Desktop/branch-open.png); }
However, ideally I wouldn't need to rely on these extra *.png files. Is there a way to include the original arrows?