Results 1 to 3 of 3

Thread: stylesheets and subcontrols

  1. #1
    Join Date
    Feb 2010
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default stylesheets and subcontrols

    Hi everybody,

    I need to customize some of the items I add inside a QTreeView.
    I was hoping to achieve this without using a delegate and override paint().

    I wanted to use setProperty() for each item and then tell the stylesheet SOMEHOW to get a different background for the items depending on that property.


    Qt Code:
    1. cpp: item->setProperty("myproperty", "customizeMe")
    2.  
    3. qss: QTreeView::item[myproperty="customizeMe"] { background=rgb(...) }
    To copy to clipboard, switch view to plain text mode 

    This does not work, the items are rendered using the default style. What options do I have? Is this NOT possible using stylesheets only?

    Thanks
    Chris

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stylesheets and subcontrols

    Quote Originally Posted by ctarsoaga View Post
    Hi everybody,

    I need to customize some of the items I add inside a QTreeView.
    I was hoping to achieve this without using a delegate and override paint().

    I wanted to use setProperty() for each item and then tell the stylesheet SOMEHOW to get a different background for the items depending on that property.
    I think that this cannot work, because the “item” children of the QTreeView must be delegate widgets created as needed by the view; setting a property on the item in the model, if that’s what you’re doing, would not make any difference in selecting a rule from the stylesheet for the view.

    If you need only to change the background, perhaps you can use either QStandardItem::setBackground, if you’re using a QStandardItemModel, or QAbstractItemModel::setItemData with Qt::BackgroundRole otherwise, to do what you want.

  3. #3
    Join Date
    Feb 2010
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: stylesheets and subcontrols

    Thanks Coises,

    I was 'afraid' of this... :-)
    I know that stylesheets are applied to widgets, and that items inside an itemview are not individual widgets...
    But when I saw the subcontrol syntax for the stylesheets e.g
    Qt Code:
    1. QTreeView::item {...}
    To copy to clipboard, switch view to plain text mode 
    I thought that maybe, there is a chance...

    I think you're right though: without using a delegate to override paint() or subclassing the model to override data(), I can't do this.

    Thank you!

Similar Threads

  1. Stylesheets & printing
    By xburgerhout in forum Qwt
    Replies: 4
    Last Post: 10th May 2010, 19:55
  2. Stylesheets
    By FuryCradle in forum Newbie
    Replies: 2
    Last Post: 26th September 2009, 21:34
  3. Stylesheets on QSplashScreen
    By GuS in forum Qt Programming
    Replies: 0
    Last Post: 16th July 2008, 14:50
  4. Replies: 5
    Last Post: 21st April 2008, 07:54
  5. stylesheets with RGB
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 01:02

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
  •  
Qt is a trademark of The Qt Company.