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 can I make my app ignore window's "HIGH DPI SCALING"?
QtWS25 Last Chance

How can I make my app ignore window's "HIGH DPI SCALING"?

Scheduled Pinned Locked Moved Solved General and Desktop
widgetsdpi awarenessscaling
15 Posts 6 Posters 11.5k 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.
  • C Offline
    C Offline
    Curtwagner1984
    wrote on 18 May 2022, 11:05 last edited by
    #1

    Greetings,

    My app's UI goes crazy when I move it to a screen that has a high DPI scaling enabled(150%) instead of (100%).
    ApplicationFrameHost_ICWuJjvmlX.png

    This is probably a sign of a bad widget design, but that's a problem for another day. For now, I just want my app to ignore the HIGH DPI SCALING option in windows if it's possible.

    I looked at this answer but I've put AA_DisableHighDpiScaling instead of AA_EnableHighDpiScaling in my main.cpp:

        QApplication a(argc, argv);
    
        QApplication::setAttribute(Qt::AA_DisableHighDpiScaling); // Disable DPI support
    

    But it has no effect. When I set the scaling to be 100% on the other screen everything is fine.

    I would appreciate it if someone knows how to make my app ignore said scaling.

    Thank You!

    J 1 Reply Last reply 18 May 2022, 11:59
    0
    • C Curtwagner1984
      18 May 2022, 11:05

      Greetings,

      My app's UI goes crazy when I move it to a screen that has a high DPI scaling enabled(150%) instead of (100%).
      ApplicationFrameHost_ICWuJjvmlX.png

      This is probably a sign of a bad widget design, but that's a problem for another day. For now, I just want my app to ignore the HIGH DPI SCALING option in windows if it's possible.

      I looked at this answer but I've put AA_DisableHighDpiScaling instead of AA_EnableHighDpiScaling in my main.cpp:

          QApplication a(argc, argv);
      
          QApplication::setAttribute(Qt::AA_DisableHighDpiScaling); // Disable DPI support
      

      But it has no effect. When I set the scaling to be 100% on the other screen everything is fine.

      I would appreciate it if someone knows how to make my app ignore said scaling.

      Thank You!

      J Online
      J Online
      J.Hilk
      Moderators
      wrote on 18 May 2022, 11:59 last edited by J.Hilk
      #2

      @Curtwagner1984 reading through the documentation of AA_DisableHighDpiScaling

      Disables high-DPI scaling in Qt, exposing window system coordinates. Note that the window system may do its own scaling, so this does not guarantee that QPaintDevice::devicePixelRatio() will be equal to 1. In addition, scale factors set by QT_SCALE_FACTOR will not be affected. This corresponds to setting the QT_AUTO_SCREEN​_SCALE_FACTOR environment variable to 0. This attribute must be set before QGuiApplication is constructed. This value was added in Qt 5.6.

      it clearly states, that attribute has to be set before the creation of the QApplication, you seem to do it afterwards.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4
      • C Offline
        C Offline
        Curtwagner1984
        wrote on 22 May 2022, 05:19 last edited by
        #3

        Thank you! For some reason I assumed this needs to be done after.

        It's like this now:

            QApplication::setAttribute(Qt::AA_DisableHighDpiScaling); // Disable DPI support
        
            QApplication a(argc, argv);
        
        
            MainWindow w;
            w.showMaximized();
            
            return a.exec();
        

        But it doesn't really seem to have an effect.

        This is how it looks on a display with 100% scaling 100 scaling and this is how it looks on a display with 150% scaling 150 scaling

        J 1 Reply Last reply 22 May 2022, 12:44
        0
        • C Curtwagner1984
          22 May 2022, 05:19

          Thank you! For some reason I assumed this needs to be done after.

          It's like this now:

              QApplication::setAttribute(Qt::AA_DisableHighDpiScaling); // Disable DPI support
          
              QApplication a(argc, argv);
          
          
              MainWindow w;
              w.showMaximized();
              
              return a.exec();
          

          But it doesn't really seem to have an effect.

          This is how it looks on a display with 100% scaling 100 scaling and this is how it looks on a display with 150% scaling 150 scaling

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 22 May 2022, 12:44 last edited by
          #4

          @Curtwagner1984 said in How can I make my app ignore window's "HIGH DPI SCALING"?:

          it doesn't really seem to have an effect.

          Try running your app in "DPI Unaware" mode: https://doc.qt.io/qt-5/highdpi.html#migrate-existing-applications

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1
          • C Offline
            C Offline
            Curtwagner1984
            wrote on 23 May 2022, 05:41 last edited by
            #5

            Thanks,
            I made a file named qt.conf with the line

            <application> -platform windows:dpiawareness=0
            

            And put it in the the folder of the executable. Nothing changed.

            Is this correct? Should application be the name of the application?

            J 1 Reply Last reply 23 May 2022, 12:44
            0
            • C Curtwagner1984
              23 May 2022, 05:41

              Thanks,
              I made a file named qt.conf with the line

              <application> -platform windows:dpiawareness=0
              

              And put it in the the folder of the executable. Nothing changed.

              Is this correct? Should application be the name of the application?

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 23 May 2022, 12:44 last edited by
              #6

              @Curtwagner1984 said in How can I make my app ignore window's "HIGH DPI SCALING"?:

              I made a file named qt.conf with the line

              <application> -platform windows:dpiawareness=0
              

              Those are command line arguments. You pass the extra arguments while launching your .exe from the Command Prompt .

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              4
              • C Offline
                C Offline
                Curtwagner1984
                wrote on 24 May 2022, 11:40 last edited by
                #7

                Thank you! This works!
                Is there a way to set it up in the application itself, without the need to provide extra command line arguments?

                J 1 Reply Last reply 24 May 2022, 11:57
                0
                • C Curtwagner1984
                  24 May 2022, 11:40

                  Thank you! This works!
                  Is there a way to set it up in the application itself, without the need to provide extra command line arguments?

                  J Online
                  J Online
                  J.Hilk
                  Moderators
                  wrote on 24 May 2022, 11:57 last edited by
                  #8

                  @Curtwagner1984
                  good old putenv, probably

                  https://www.cprogramming.com/fod/putenv.html


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  JonBJ 1 Reply Last reply 24 May 2022, 12:13
                  0
                  • J J.Hilk
                    24 May 2022, 11:57

                    @Curtwagner1984
                    good old putenv, probably

                    https://www.cprogramming.com/fod/putenv.html

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 24 May 2022, 12:13 last edited by
                    #9

                    @J-Hilk
                    I looked at this. What environment variable name (and value) are you proposing for -platform windows:dpiawareness=0, I could not see that it worked this way??

                    J 1 Reply Last reply 24 May 2022, 12:18
                    0
                    • JonBJ JonB
                      24 May 2022, 12:13

                      @J-Hilk
                      I looked at this. What environment variable name (and value) are you proposing for -platform windows:dpiawareness=0, I could not see that it worked this way??

                      J Online
                      J Online
                      J.Hilk
                      Moderators
                      wrote on 24 May 2022, 12:18 last edited by J.Hilk
                      #10

                      @JonB admittedly
                      the official way to do it, is apparently the creation and deployment of a qt.conf file, same level as the executable with this content:

                      [Platforms]
                      WindowsArguments = dpiawareness=0

                      that said:

                      qputenv("dpiawareness", "0"); or qputenv("windows:dpiawareness", "0");

                      I'm unsure, I'm not using it often enough :D


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      JonBJ C 2 Replies Last reply 24 May 2022, 12:27
                      2
                      • J J.Hilk
                        24 May 2022, 12:18

                        @JonB admittedly
                        the official way to do it, is apparently the creation and deployment of a qt.conf file, same level as the executable with this content:

                        [Platforms]
                        WindowsArguments = dpiawareness=0

                        that said:

                        qputenv("dpiawareness", "0"); or qputenv("windows:dpiawareness", "0");

                        I'm unsure, I'm not using it often enough :D

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 24 May 2022, 12:27 last edited by JonB
                        #11

                        @J-Hilk said in How can I make my app ignore window's "HIGH DPI SCALING"?:

                        qputenv("dpiawareness", "0"); or qputenv("windows:dpiawareness", "0");
                        I'm unsure, I'm not using it often enough :D

                        There is/I can see no evidence that a Qt program would recognise either of these proposed environment variable names. Unless you can see where it says it does.... I see only the command line or qt.conf file approaches so far.

                        1 Reply Last reply
                        0
                        • J J.Hilk
                          24 May 2022, 12:18

                          @JonB admittedly
                          the official way to do it, is apparently the creation and deployment of a qt.conf file, same level as the executable with this content:

                          [Platforms]
                          WindowsArguments = dpiawareness=0

                          that said:

                          qputenv("dpiawareness", "0"); or qputenv("windows:dpiawareness", "0");

                          I'm unsure, I'm not using it often enough :D

                          C Offline
                          C Offline
                          Curtwagner1984
                          wrote on 30 May 2022, 05:19 last edited by
                          #12

                          @J-Hilk said in How can I make my app ignore window's "HIGH DPI SCALING"?:

                          [Platforms]
                          WindowsArguments = dpiawareness=0

                          Thank you! I tried to used this before but I've put incorrect syntax in this file. This works.

                          1 Reply Last reply
                          2
                          • A Offline
                            A Offline
                            arunkannan
                            wrote on 2 Sept 2024, 13:52 last edited by
                            #13

                            @Curtwagner1984 @JonB @J-Hilk @JKSH
                            I used Python PyQt5-5.15 for my application
                            I have guimain.exe and panelgui.ui files . Made qt.conf file
                            But when I change windows scaling to 125% or 150% the text fonts and other ui widgets get messed up...how to make it work i.e disable windows scaling for application

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              Violet Giraffe
                              wrote on 5 Nov 2024, 08:50 last edited by Violet Giraffe 11 May 2024, 10:44
                              #14

                              In Qt 6 you can override the scale factor with the QT_SCALE_FACTOR env variable, but there is a problem: it doesn't set the factor to your value, it multiplies it. For example, if the system has 150% and you want 100%, you need to set QT_SCALE_FACTOR to 0.666667 (and even then it might not end up exactly 1.0 but rather 1.0001).

                              Is this intentional? There is a number of problems resulting from this multiplicative behavior, the primary one being when the application is moved between screens with different scale factors. I want to have 1.0 everywhere, not 0.66!

                              Also, -platform windows:dpiawareness=0 DOES NOT WORK!
                              Or, rather, it does the wrong thing. It disables too much, devicePixelRatio() reports 1.0 but the window is stretched and blurry.

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                Violet Giraffe
                                wrote on 5 Nov 2024, 11:54 last edited by
                                #15

                                Found the proper option: QT_ENABLE_HIGHDPI_SCALING=0.

                                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