How do i change the "Expansion Symbol" in QTreeView from an arrow [see the attached pic] to a plus (+) sign?
Printable View
How do i change the "Expansion Symbol" in QTreeView from an arrow [see the attached pic] to a plus (+) sign?
I forgot to mention that this is on MacOS and am using Qt 5.15.2. Thanks.
You can use style sheets for it: https://doc.qt.io/qt-5/stylesheet-reference.html
The only option appears to be QApplication::setStyle(QStyleFactory::create("windows")). If I get QTreeView::branch options for the style sheet to work, I will report back (currently I am not able to).
OK, I am trying really hard to get this to work. I have copied the QTreeView example from the customization examples page, have copied all of the images they include in that example and have added them to my QRC file. The absolute URL path to the images should be ":/Resources/stylesheet-vline.png" for example, which I know works because I can use it to set a toolbar icon.Quote:
You can use style sheets for it
I can't get any of the images to appear. I have tried every variation on the URL path: no ":", no ":/", no ":/Resources", but get nowhere. I think the stylesheet is getting processed correctly, because the default icons are gone, too. (Prior to this, I had some extra whitespace in the stylesheet string, and the default icons didn't change when the sheet was loaded).
I have also tried a minimal stylesheet with only the "QTreeView::branch:has-siblings:adjoins-item" clause to see if I could get just one of the icons to show up, but no luck.
Any suggestions? Here is the complete stylesheet QString (without the URL prefixes):
Code:
border-image: url( stylesheet-vline.png ) 0;\ }\ \ QTreeView::branch:has-siblings:adjoins-item {\ border-image: url( stylesheet-branch-more.png ) 0;\ }\ \ QTreeView::branch:!has-children:!has-siblings:adjoins-item {\ border-image: url( stylesheet-branch-end.png ) 0;\ }\ \ QTreeView::branch:has-children:!has-siblings:closed,\ QTreeView::branch:closed:has-children:has-siblings {\ border-image: none;\ image: url( stylesheet-branch-closed.png );\ }\ \ QTreeView::branch:open:has-children:!has-siblings,\ QTreeView::branch:open:has-children:has-siblings {\ border-image: none;\ image: url( stylesheet-branch-open.png );\ }";
Works fine for me. First tested with local png files (don't forget to rename them after downloading) to use the exact same stylesheet as in the example - all works as expected.
Then I added a qrc file placed all files under :/test/, changed urls to 'url(:/test/vline.png)' and it still works.
Why should that matter if I use the names of the downloaded files in my URL and in the qrc file? (I.e. with the prepended "stylesheet-" string).Quote:
don't forget to rename them after downloading
Anyway, renaming the files and re-importing them into the qrc file makes no difference. My qrc file lives in a "Resources" subdirectory of my project, so it forces a "/Resources" prefix onto all of the resource paths. The resource string shows in the qrc editor as ":/Resources/whatever.png", and I know this to be valid from using it to set an icon in a tool bar.
I have tried setting this stylesheet directly onto the QTreeView as well as onto the dialog that contains the QTreeView, but it makes no difference.
I guess I will have to write a minimal example and beat on that until I get it to work.
Edit: I don't believe it. I changed from:
to:Code:
url( :/Resources/branch-more.png )
and now it works. What kind of a specification language cares about white space except in variable names? Geez.Code:
url(:/Resources/branch-more.png)
It should not matter. Will maybe take a look on it :)
Thank you both, I got it to work as well.