Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When is the StyleSheet applied? - Not seeing 'font' updated.
Forum Updated to NodeBB v4.3 + New Features

When is the StyleSheet applied? - Not seeing 'font' updated.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 301 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PValentine
    wrote on last edited by
    #1

    Using Qt Designer I have a QDialog that includes an empty (at design time) QTableWidget.
    The Dialog has the following Stylesheet (as set in the designer):

    QTableView { font-size: 22pt; background-color: black; color: white; selection-background-color: black; selection-color: white; }
    QHeaderView { font: normal "Sans Serif"; font-size: 20pt; background-color: grey; color: white; }
    QHeaderView::down-arrow { image: url(:/UiImages/down_24.png); }
    QHeaderView::up-arrow { image: url(:/UiImages/up_24.png); }
    

    Now in my code I add QTableWidgetItem to the table:

        QTableWidgetItem* item = new QTableWidgetItem(name);
        item->setFlags(Qt::ItemIsEnabled); // Disable the selectable, editable, dragable etc (keep "Enabled)
    
        ui.tableWidget->setItem(row, 2, item);
        QFont font = item->font();
        qDebug() << "Font Size is"<<font.pointSize()<<"incrementing to"<<font.pointSize()+4;
        font.setPointSize(font.pointSize()+4);
        item->setFont(font); // <--- THIS LINE
        ui.tableWidget->resizeRowToContents(row);
    

    When I read the font size the debug statement shows it as "9", which is not what the stylesheet indicated. If I setFont then it will be set to 13 (9+4), and then appear small on the screen.
    If I do NOT call setFont, then the text appears on the screen at size 22 as per the stylesheet... (but reading the fontsize from the widget still returns 9).

    It seems that the wordwrap is also not working correctly since it seems to be determined on the fontsize (9), not the fontsize that the text is actually being rendered as (22) so I always get ellipsed long text.

    When (or what) should I read the font size in order to get the size as set per the stylesheet?
    I thought that the widget font data would be updated to match the stylesheet?

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • P PValentine

      Using Qt Designer I have a QDialog that includes an empty (at design time) QTableWidget.
      The Dialog has the following Stylesheet (as set in the designer):

      QTableView { font-size: 22pt; background-color: black; color: white; selection-background-color: black; selection-color: white; }
      QHeaderView { font: normal "Sans Serif"; font-size: 20pt; background-color: grey; color: white; }
      QHeaderView::down-arrow { image: url(:/UiImages/down_24.png); }
      QHeaderView::up-arrow { image: url(:/UiImages/up_24.png); }
      

      Now in my code I add QTableWidgetItem to the table:

          QTableWidgetItem* item = new QTableWidgetItem(name);
          item->setFlags(Qt::ItemIsEnabled); // Disable the selectable, editable, dragable etc (keep "Enabled)
      
          ui.tableWidget->setItem(row, 2, item);
          QFont font = item->font();
          qDebug() << "Font Size is"<<font.pointSize()<<"incrementing to"<<font.pointSize()+4;
          font.setPointSize(font.pointSize()+4);
          item->setFont(font); // <--- THIS LINE
          ui.tableWidget->resizeRowToContents(row);
      

      When I read the font size the debug statement shows it as "9", which is not what the stylesheet indicated. If I setFont then it will be set to 13 (9+4), and then appear small on the screen.
      If I do NOT call setFont, then the text appears on the screen at size 22 as per the stylesheet... (but reading the fontsize from the widget still returns 9).

      It seems that the wordwrap is also not working correctly since it seems to be determined on the fontsize (9), not the fontsize that the text is actually being rendered as (22) so I always get ellipsed long text.

      When (or what) should I read the font size in order to get the size as set per the stylesheet?
      I thought that the widget font data would be updated to match the stylesheet?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @PValentine said in When is the StyleSheet applied? - Not seeing 'font' updated.:

      I thought that the widget font data would be updated to match the stylesheet?

      No, this is not possible since the widget has no knowledge how it is drawn by the stylesheet.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • P PValentine

        Using Qt Designer I have a QDialog that includes an empty (at design time) QTableWidget.
        The Dialog has the following Stylesheet (as set in the designer):

        QTableView { font-size: 22pt; background-color: black; color: white; selection-background-color: black; selection-color: white; }
        QHeaderView { font: normal "Sans Serif"; font-size: 20pt; background-color: grey; color: white; }
        QHeaderView::down-arrow { image: url(:/UiImages/down_24.png); }
        QHeaderView::up-arrow { image: url(:/UiImages/up_24.png); }
        

        Now in my code I add QTableWidgetItem to the table:

            QTableWidgetItem* item = new QTableWidgetItem(name);
            item->setFlags(Qt::ItemIsEnabled); // Disable the selectable, editable, dragable etc (keep "Enabled)
        
            ui.tableWidget->setItem(row, 2, item);
            QFont font = item->font();
            qDebug() << "Font Size is"<<font.pointSize()<<"incrementing to"<<font.pointSize()+4;
            font.setPointSize(font.pointSize()+4);
            item->setFont(font); // <--- THIS LINE
            ui.tableWidget->resizeRowToContents(row);
        

        When I read the font size the debug statement shows it as "9", which is not what the stylesheet indicated. If I setFont then it will be set to 13 (9+4), and then appear small on the screen.
        If I do NOT call setFont, then the text appears on the screen at size 22 as per the stylesheet... (but reading the fontsize from the widget still returns 9).

        It seems that the wordwrap is also not working correctly since it seems to be determined on the fontsize (9), not the fontsize that the text is actually being rendered as (22) so I always get ellipsed long text.

        When (or what) should I read the font size in order to get the size as set per the stylesheet?
        I thought that the widget font data would be updated to match the stylesheet?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @PValentine
        As @Christian-Ehrlicher has said, you cannot read the effects of stylesheet in Qt code.

        Try not to set font in code at the same time as using stylesheets. Are you aware there is a QTableView::item CSS selector? This affects all the table's items, there isn't a way of selecting individual ones.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved