How do i change the "Expansion Symbol" in QTreeView from an arrow [see the attached pic] to a plus (+) sign?
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
d_stranz (18th February 2021)
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.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):
Qt 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 );\ }";To copy to clipboard, switch view to plain text mode
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
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).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:Qt Code:
url( :/Resources/branch-more.png )To copy to clipboard, switch view to plain text mode
and now it works. What kind of a specification language cares about white space except in variable names? Geez.Qt Code:
url(:/Resources/branch-more.png)To copy to clipboard, switch view to plain text mode
Last edited by d_stranz; 18th February 2021 at 21:44.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
It should not matter. Will maybe take a look on it![]()
Thank you both, I got it to work as well.
Bookmarks