PDA

View Full Version : QTreeView items - different stylesheet for root and childs - is it possible?



Kostanev
5th December 2010, 12:34
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.

tbscope
5th December 2010, 12:39
Yes, see the ::item sub control
You probably need names or another property to differentiate between the root item and a child item.

Kostanev
5th December 2010, 12:54
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.

tbscope
5th December 2010, 13:28
You can set a custom type for example.
And read this:
http://doc.qt.nokia.com/4.7/stylesheet-examples.html#customizing-using-dynamic-properties

Kostanev
5th December 2010, 13:41
I'm afraid, that QStandardItem has no setProperty() and setObjectName() methods?

tbscope
5th December 2010, 13:53
Hmm, it's indeed not a qobject.

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

lmoran
6th December 2010, 19:19
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.

tbscope
7th December 2010, 04:36
http://doc.qt.nokia.com/4.7/qproxystyle.html