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.
Code:
cpp: item->setProperty("myproperty", "customizeMe")
qss
: QTreeView::item[myproperty
="customizeMe"] { background
=rgb
(...
) }
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
Re: stylesheets and subcontrols
Quote:
Originally Posted by
ctarsoaga
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.
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 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!