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. Dynamic scaling UI components in Qt Creator
Forum Updated to NodeBB v4.3 + New Features

Dynamic scaling UI components in Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 6 Posters 574 Views 2 Watching
  • 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.
  • T Offline
    T Offline
    tdc0311
    wrote on last edited by
    #1

    Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!Screenshot 2024-08-07 094500.png Screenshot 2024-08-07 094144.png Screenshot 2024-08-07 094433.png

    C Pl45m4P 2 Replies Last reply
    0
    • T tdc0311

      Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!Screenshot 2024-08-07 094500.png Screenshot 2024-08-07 094144.png Screenshot 2024-08-07 094433.png

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @tdc0311 said in Dynamic scaling UI components in Qt Creator:

      I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app.

      Then you have to do all the work yourself. I am going to assume you are using Windows.

      You might be able to detect the scaling change in a handler attached to QCoreApplication::installNativeEventFilter(). You'd be looking for WM_DPICHANGED I guess. Not sure if there is a Qt-translated version present in the Qt event system.

      BTW: Nothing in your screenshots look like it could not be done with layouts. Only you know what the rest of it looks like though.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bonnie
        wrote on last edited by
        #3

        I'd rather disable high dpi scaling in Qt if layout is not available.

        1 Reply Last reply
        0
        • T tdc0311

          Hi so i'm working on a project with qt, i design my app and all of its ui component in 100% scale screen, but when i change my screen resolution to 150%, it shrunk and can't scale back, and when i change back to 100% this happens. So i want to ask if there's any way that i can dynamically scaling my app or is there any other way that i can make my app responsive. I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app. Thanks!!!!Screenshot 2024-08-07 094500.png Screenshot 2024-08-07 094144.png Screenshot 2024-08-07 094433.png

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @tdc0311 said in Dynamic scaling UI components in Qt Creator:

          I can't use box layouts or any layouts because my app has a lot of different labels, buttons and many other ui components that are placed in many places in my app.

          Why you think so? From looking at your design I don't know what prevents you from using layouts.
          At least some layout(s) like cascading vertical/horizonal layouts should work.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • J Offline
            J Offline
            John Van
            wrote on last edited by John Van
            #5

            Try using this code.
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
            QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
            QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
            Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code?

            Pl45m4P 1 Reply Last reply
            0
            • J John Van

              Try using this code.
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
              QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
              QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
              Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code?

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @John-Van said in Dynamic scaling UI components in Qt Creator:

              Also, is the main page using QTabWidget? It looks very nice. Would you mind sharing this part of the code?

              Either this or a heavily styled QStackedWidget with buttons on the left to activate and show the matching page widget.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #7

                I am not sure if you need to support someone changing the system settings while your app is open. It is such an edge case that I would say it is okay for the user to close and reopen the app. However, this problem might occur when having two monitors with different scaling each. For this we react to showEvent, resizeEvent, and moveEvent to detect when the pixel ratio of the screen changes.

                1 Reply Last reply
                1

                • Login

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