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. How to ensure the QFrame title is scaled automatically with the window's text size scaling?
QtWS25 Last Chance

How to ensure the QFrame title is scaled automatically with the window's text size scaling?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qframeqwidgettitle barqt5.6highdpi
6 Posts 2 Posters 2.0k 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.
  • J Offline
    J Offline
    johnyang
    wrote on last edited by johnyang
    #1

    I have a custom panel implementation that is inherited from QFrame. I can set the title by using the setWindowTitle() function. I noticed that I can not set the font size of this title, but I was expecting that this title will be scaled based on Windows 10's text scaling. I am using a 4K monitor and I am hoping the text can be scaled by windows setting, but that doesn't seem to be the case. I have set both QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling) and QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps) so the whole application and pixel images are scaled correctly.

    However, the title text of each custom panel is not affected by the Window 10's make text bigger setting, while the main application windows's title text is scaled properly and those text that is painted by using DrawText functions are scaled properly. However, my custom widget's title is not scaled properly.

    My custom widget is also loaded into a QDockWidget. I can modify the font size of the title directly but I am hoping it will be scaled properly like the application title bar.

    Is there anything I can do to have the title of the custom widget scaling based on the window 10 setting?

    A simplified code example to help you to understand the problem:
    My main application has a dockwidget and a custom 'panel' (inherited by a QFrame or QWidget) is attached to it. (See code below)

    QDockWidget* dock = new QDockWidget(panel->Title(), this);
    dock->setObjectName(panel->TypeId());
    dock->setAllowedAreas(panel->AllowedDockAreas());
    dock->setFeatures(dock->features() & ~QDockWidget::DockWidgetFloatable);
    dock->setWidget(panel);
    dock->setVisible(panel->DefaultVisible());
    addDockWidget(panel->DefaultDockArea(), dock);
    

    So if I add the following code, I can adjust the font size of the title directly but it is a manual change by myself. What I want is to have it automatically scaled based on the Windows's text scaling factor (e.g. 150%, 200% etc)

    QFont f = dock->font();
    f.setPointSizeF(f.pointSizeF()*devicePixelRatioF());
    dock->setFont(f);
    

    So my question is how to or whether it is possible to have the title of this custom panel to be scaled by the window 10's text scaling factor in control panel (especially in a high dpi situation)?

    Updates:
    It looks like the font and titlebar height are exactly the same between the custom panel and the main application. I also tried to set a WindowsFlag to the custom panel to be Qt::Desktop, so the panel becomes a standalone window and finally has its title text scaled with the Windows setting. So it looks like the Windows Manager is actually treating widget differently when painting it on the display. Maybe the only option is to have the custom titlebar for the dockwidget?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      0
      • J Offline
        J Offline
        johnyang
        wrote on last edited by johnyang
        #3

        @SGaist I'm with 5.6.

        And interestingly, I used the following code to obtain the height of the title bar and surprisingly in any scale factor, the title bar of the application and the title bar of the custom widget gives the same value, despite they actually look different. These numbers do change when the text scaling factor changes. Does that mean it is actually how Window handles applications and its subsidiary widgets differently when dealing with scaling in display?

        auto dw_style = dock->style();
        int titleBarHeight = dw_style->pixelMetric(QStyle::PM_TitleBarHeight);
        int titleBarMargin = dw_style->pixelMetric(QStyle::PM_DockWidgetTitleMargin);

        auto main_style = this->style();
        int main_titleBarHeight = main_style->pixelMetric(QStyle::PM_TitleBarHeight);
        int main_titleBarMargin = main_style->pixelMetric(QStyle::PM_DockWidgetTitleMargin);

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          What version of Qt are you using ?

          J Offline
          J Offline
          johnyang
          wrote on last edited by
          #4

          @SGaist To be more precisely, I'm with 5.6.1

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You might want to consider using a more recent version of Qt, the latest LTS is 5.12.6 and the current stable is 5.14.0. There's been a lot of work put into the high DPI support since Qt 5.6.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • SGaistS SGaist

              You might want to consider using a more recent version of Qt, the latest LTS is 5.12.6 and the current stable is 5.14.0. There's been a lot of work put into the high DPI support since Qt 5.6.

              J Offline
              J Offline
              johnyang
              wrote on last edited by johnyang
              #6

              @SGaist I tried the Qt 5.12.6 and it did the trick! Thanks.

              But interestingly, the title of the main application is no longer scaled by "Make text bigger" setting but the dockwidget ones does. I guess that there is an intention not to scale the main title. "Make everything bigger" setting does scale everything properly now except the titlebar height of only the main application looks not enough for the enlarged font size. I will give qt5.14 a try as well.

              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