PDA

View Full Version : stylesheets and subcontrols



ctarsoaga
1st February 2010, 13:08
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.



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

Coises
1st February 2010, 21:45
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 (http://doc.trolltech.com/latest/qt.html#ItemDataRole-enum) otherwise, to do what you want.

ctarsoaga
2nd February 2010, 08:19
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
QTreeView::item {...} 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!