PDA

View Full Version : How to style QTableView headers using stylesheets?



p.csakany
23rd October 2010, 20:09
Hello,

I am trying to configure the look of a QTableView widget. I applied a style sheet to my main form which is taken up buy all its children including the QTableView.

Once I add a model to the QTableView object the headers appear. The colour of the text is according to the style sheet but the background I cannot configure.

The applied style sheet is:
*{
background-color: qlineargradient(spread:pad, x1:1, y1:0.813, x2:1, y2:0, stop:0 rgba(87, 87, 87, 255), stop:1 rgba(135,135, 135, 255));
border: 2px solid gray;
border-radius: 10px;
padding: 0 8px;
color: rgb(255, 255, 255);
}

The part of the header without column text is nice with rounded corners and shaded gray, so is the background f the table. The header text is white as it should be but the text background is light gray instead of shaded.
Please see screen shot below:

5390

How can I configure QTableView to have a smooth continues shaded header via style sheets?

Thanks

ChrisW67
23rd October 2010, 22:48
Customising QHeaderView (http://doc.qt.nokia.com/latest/stylesheet-examples.html#customizing-qheaderview) useful?

p.csakany
23rd October 2010, 23:26
I thought of that. I previously added this:

QHeaderView {
background: rgb(255, 255, 127);
}

Had no effect what so ever on column heads. However it changed the colour of the header outside of the column heads to yellow.

Unfortunatelly, the question remains; How do you change the background of the column heads?

ChrisW67
24th October 2010, 05:54
The example does exactly what you are asking for. You need to style the QHeaderView::section background, not the header view background.

p.csakany
24th October 2010, 21:50
It worked,

I have not realised that I have to use QHeaderView::section.

Thank you for your help!