QTreeview Styling


#1

I’ve been slowly teaching myself Qt styling in order to better create a visually cohesive set of tools. I’ve been doing this by taking an existing piece of software that takes CSS sheets and changing it to see what I can do, working my way through all the various widgets available in the online documentation. I’m pretty happy with my grasp so far, but I am stuck on how to style the items in QTreeview.

By default the software has a scheme like this:
want

When I use QTreeView::item:has-children { } I get this:
get

I can also get this by specifying has-siblings or adjoins-item:
get2

I tried using nth-child(2) to grab the second level, but that just breaks a bunch of stuff. Is there any way via the CSS stylesheet to specifically style individual levels in the tree?

Thanks,

j


#2

Not sure about individual levels (perhaps is top level widget/item).
What about alternate item background?


#3

Hmm I can’t seem to find a stylesheet property to check for top level items.
Probably need to use a custom delegate with a paint override using the items data to determine how it should be represented?


#4

Or actually, you could cheat it with a custom property on the item and a property check in the stylesheet? Seems dirty but should do the trick?
https://wiki.qt.io/Dynamic_Properties_and_Stylesheets


#5

I’ve emailed the current maintainer of the program I’m editing to see if these have a tag, but it looks like you cannot differentiate between levels just using CSS unfortunately. I was hoping it would work like web CSS where you could use child levels. Oh well.

Thanks for the suggestions.