Results 1 to 5 of 5

Thread: QTreeWidget: How to display the root item?

  1. #1
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeWidget: How to display the root item?

    Hello.
    I'm building a Qt application with a QTreeWidget. I've got several TopLevelItems each with some childs. But all the Items are "hanging" on the top end of the QTreeWidget like this:
    Qt Code:
    1. |
    2. [-]TopLevelItem1
    3. | |
    4. | -Child1
    5. | |
    6. | -Child2
    7. |
    8. [-]TopLevelItem2
    9. |
    10. -Child3
    To copy to clipboard, switch view to plain text mode 
    I read in the documentation that there is a "invisibleRootItem", but I got no success to make it visible.
    How can I display the root item?
    I wanted to have a tree like this:
    Qt Code:
    1. RootItem
    2. |
    3. [-]TopLevelItem1
    4. | |
    5. | -Child1
    6. | |
    7. | -Child2
    8. |
    9. [-]TopLevelItem2
    10. |
    11. -Child3
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget: How to display the root item?

    You don't want to make it visible. You want to set rootIsDecorated property to false.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Johannes (22nd February 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget: How to display the root item?

    My primary intention was to display the root item, but your suggestion to try the property rootIsDecorated lead also to a good looking result.
    I tried it and now my topLevelItems are childs and my new topLevelItem looks like a root item. Thanks!

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget: How to display the root item?

    You can't display the invisibleRootItem because it is a fake item used only to have an equivalent of empty QModelIndex.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    Johannes (22nd February 2011)

  7. #5
    Join Date
    Jan 2011
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget: How to display the root item?

    That's a good reason. Thanks for the explanation.

Similar Threads

  1. display a directory using qtreewidget
    By kamlmish in forum Newbie
    Replies: 2
    Last Post: 19th December 2010, 13:37
  2. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 11:45
  3. Replies: 1
    Last Post: 20th January 2010, 09:38
  4. QTreeWidget select item
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2007, 15:26
  5. Get a certain item from a QTreeWidget
    By mace in forum Newbie
    Replies: 2
    Last Post: 28th August 2006, 11:35

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.