Results 1 to 9 of 9

Thread: QTreeView: change expansion symbol

  1. #1
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    30
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question QTreeView: change expansion symbol

    How do i change the "Expansion Symbol" in QTreeView from an arrow [see the attached pic] to a plus (+) sign?
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    30
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    I forgot to mention that this is on MacOS and am using Qt 5.15.2. Thanks.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    541
    Thanked 83 Times in 78 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    You can use style sheets for it: https://doc.qt.io/qt-5/stylesheet-reference.html

  4. The following user says thank you to ChristianEhrlicher for this useful post:

    d_stranz (18th February 2021)

  5. #4
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    30
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    Quote Originally Posted by ChristianEhrlicher View Post
    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).

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,940
    Thanks
    276
    Thanked 803 Times in 792 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTreeView: change expansion symbol

    You can use style sheets for it
    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.

    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:
    1. static QString sTreeStyle = "QTreeView::branch:has-siblings:!adjoins-item {\
    2. border-image: url( stylesheet-vline.png ) 0;\
    3. }\
    4. \
    5. QTreeView::branch:has-siblings:adjoins-item {\
    6. border-image: url( stylesheet-branch-more.png ) 0;\
    7. }\
    8. \
    9. QTreeView::branch:!has-children:!has-siblings:adjoins-item {\
    10. border-image: url( stylesheet-branch-end.png ) 0;\
    11. }\
    12. \
    13. QTreeView::branch:has-children:!has-siblings:closed,\
    14. QTreeView::branch:closed:has-children:has-siblings {\
    15. border-image: none;\
    16. image: url( stylesheet-branch-closed.png );\
    17. }\
    18. \
    19. QTreeView::branch:open:has-children:!has-siblings,\
    20. QTreeView::branch:open:has-children:has-siblings {\
    21. border-image: none;\
    22. image: url( stylesheet-branch-open.png );\
    23. }";
    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    541
    Thanked 83 Times in 78 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    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.

  8. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,940
    Thanks
    276
    Thanked 803 Times in 792 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTreeView: change expansion symbol

    don't forget to rename them after downloading
    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).

    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:
    Qt Code:
    1. url( :/Resources/branch-more.png )
    To copy to clipboard, switch view to plain text mode 
    to:
    Qt Code:
    1. 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.
    Last edited by d_stranz; 18th February 2021 at 20: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.

  9. #8
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    541
    Thanked 83 Times in 78 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    It should not matter. Will maybe take a look on it

  10. #9
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    30
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView: change expansion symbol

    Thank you both, I got it to work as well.

Similar Threads

  1. QTreeView expansion after model reset
    By d_stranz in forum Qt Programming
    Replies: 3
    Last Post: 3rd December 2014, 23:42
  2. Replies: 3
    Last Post: 27th May 2014, 17:55
  3. Replies: 1
    Last Post: 22nd June 2010, 19:56
  4. Replies: 2
    Last Post: 6th May 2010, 14:09
  5. Suppress QSettings Expansion of @ Symbol
    By ChrisW67 in forum Newbie
    Replies: 0
    Last Post: 19th April 2010, 04:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.