Qt stylesheets: QHeaderView draws header text in bold when view data is selected


Question

I'm trying to style a QTableView with Qt Stylesheets. Everything works OK, except that all the table header texts (column headers) are drawn as bold text whenever data in the table view is selected.

I've tried things like this:

QTableView::section {
    font-weight: 400;
}
QTableView::section:selected {
    font-weight: 400;
}

QHeaderView {
    font-weight: 400;
}

QHeaderView::section {
    font-weight: 400;
}

to no avail.

Can anyone point me in the right direction, ideally using stylesheets?

1
13
10/1/2009 2:40:03 PM

Accepted Answer

I haven't tested it, but setting the QHeaderView::highlightSections property to false should do the trick.

You can get a pointer to a QHeaderView object using QTableView's verticalHeader() and horizontalHeader() methods.

22
9/1/2016 11:14:34 AM

In Qt Designer UI format you can use the attribute horizontalHeaderHighlightSections:

 <widget class="QTableView" name="m_studyList">
  <attribute name="horizontalHeaderHighlightSections">
   <bool>false</bool>
  </attribute>

But it also completely disables css for selected columns.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon