Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95578

QTableWidget/QTableView ignores font property when application style sheet is set, even without QTableWidget styles

    XMLWordPrintable

Details

    • Linux/X11

    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.

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jirauser48520 user-2cd08 (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes