Skip to content
Advertisement

Control display of gridlines and borders in header of QTreeView

(W10 platform)

What I’m trying to get (I was asked to produce a target outcome, with Gimp): what I want

What I currently get:

current result

MRE:

JavaScript

What I’m trying to do here is 1) change the grid lines in the horizontal header; 2) put a solid line of some kind between the header and the data rows of the table. Uncomment my attempts if interested.

I’m not clear whether overriding functionality to do with ItemDataRole is the way to go here: I can’t see any way that this functionality actually takes care of grid lines… Or whether style sheets should do this.

It seems that it may be significant that I’m working on a W10 machine (i.e. more understandable results may possibly be obtained in Linux/OS).

Image of attempt1: failed attempt 1

Image of attempt2: failed attempt 2

Image of attempt3: failed attempt 3

Advertisement

Answer

What you’re trying to style is the table header (a QHeaderView), not the table.

So, you should apply the stylesheet to it, and use the correct class::selector:state syntax.

JavaScript

Note that since in the example I’ve set the stylesheet to the horizontal header, the :horizontal selector can be omitted (but the ::section is required).

Also consider that you could still set the stylesheet above to the table: its syntax will be correctly applied since I’ve correctly used the class selector. The problem is that, since we need to show a border for the whole header, it has to be applied to the class without selectors, which will obviously cause both headers to show a bottom border, and that’s because in this case :horizontal won’t work properly (AFAIK).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement