Results 1 to 8 of 8

Thread: QTreeView items - different stylesheet for root and childs - is it possible?

  1. #1
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTreeView items - different stylesheet for root and childs - is it possible?

    Hello All,

    I'm going to create a contact list for my app with groups and I'm using QTreeView with a model. My question is: Can I stylize the root element with style different from the childs or some other trick(s) to specify different stylesheet for each item.


    Thanks in advance for all responses.
    Last edited by Kostanev; 5th December 2010 at 13:53. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    Yes, see the ::item sub control
    You probably need names or another property to differentiate between the root item and a child item.

  3. #3
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    Hi tbscope,

    I'm currently using ::item, but it sets stylesheet to all items and this is not a solution. Can you explain me what property I should use.
    QStandardItem has no setObjectName method, so I can't use it to differentiate the items.

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    You can set a custom type for example.
    And read this:
    http://doc.qt.nokia.com/4.7/styleshe...mic-properties

  5. #5
    Join Date
    Sep 2007
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    I'm afraid, that QStandardItem has no setProperty() and setObjectName() methods?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    Hmm, it's indeed not a qobject.

    Well, then you'll need to create your own style.
    Try a custom proxy style.

  7. #7
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?

    I'm sorry for my ignorance, but what is a custom proxy style? (I've searched thru the forum and couldn't find it, can you post any reference if it exists?)
    I'm having the same problem that originated this post.

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTreeView items - different stylesheet for root and childs - is possible?


  9. The following user says thank you to tbscope for this useful post:

    lmoran (7th December 2010)

Similar Threads

  1. QTreeView: include root in tree?
    By meter in forum Newbie
    Replies: 2
    Last Post: 14th June 2010, 12:59
  2. Replies: 1
    Last Post: 10th June 2010, 05:35
  3. Direct root childs inline QTreeView
    By faraslacks in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 07:45
  4. QTreeView: make root decoration appear on visual column 0
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2008, 02:36
  5. QTreeView rows (items) StyleSheet
    By Kostanev in forum Qt Programming
    Replies: 1
    Last Post: 15th September 2007, 10:36

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.