Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14.1, 5.15.2
-
None
Description
I want to customize the header font of a table by using setFont(). This worked fine so far (see attached screen shot expected_QTableView_both_fonts_small.png).
Now I customized another widget via stylesheet that I have set application wide - completely unreleated to QTableWidget. As soon as I call qApp->setStyleSheet(), QTableWidget/QTableView or rather QHeaderView ignores the font property completely.
Consider the following code:
int main(int argc, char *argv[]) { QApplication a(argc, argv); // #1: comment-out next line to fix problem qApp->setStyleSheet("/* bla */"); QTableWidget w; w.setRowCount(1); w.setColumnCount(2); w.setHorizontalHeaderLabels(QStringList() << "short" << "very long captions"); QFont f = w.font(); f.setPointSize(5); w.setFont(f); w.horizontalHeader()->setFont(f); // #2: comment-in next line to fix problem //w.horizontalHeader()->setStyleSheet("QHeaderView::section:horizontal {font-size:5pt;}"); w.setItem(0,0, new QTableWidgetItem("B")); w.setItem(0,1, new QTableWidgetItem("A")); w.show(); return a.exec(); }
See comment #1: In the next line I set a dummy style sheet (just a comment). Still, my custom font in the header view is no longer used (result, see attached screenshot 'QTableWidget_tableFontCorrect_headerFontWrong.png'). You can comment-out the line following the comment to see the effect. It clearly only affects the headerview.
Now see comment #2: This is the only way to fix the headerView so far - I need to do this for each instance of a customized QTableWidget in my code. Activate the line following comment #2 and even with the application-wide stylesheet, now the widget and its header use the correct font.
It looks as if the item view and the header view handle style sheets differently. From my understanding the header view should only adjust its appearance when the application-wide style sheet actually contains anything QHeaderView-related. Otherwise the default behavior, i.e. using own font-property, should be used. Hence, I consider this a bug.