Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. High DPI scaling of QQuickItem derived object
Forum Update on Monday, May 27th 2025

High DPI scaling of QQuickItem derived object

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 2.4k 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
    polaris
    wrote on last edited by
    #1

    Hello,

    I use QtQuickControls 2 together with QQuickItem-derived class in my app. After I set AA_EnableHighDpiScaling attribute and all QQuickControls 2 components look correctly on my smartphone but object of my custom class is scaled incorrectly. Here is the app without HighDpi scaling with minimum zoom(the way it is meant to work):

    http://pasteboard.co/6dmRQpVaZ.png

    And here is the one with scaling with minimum zoom:

    http://pasteboard.co/CxdoQ7rr.png

    It seems that on the second screen the object is scaled too much and I can see square pixels of all textures that I draw with QPixmap or QImage. However, the images that I load from external memory and nodes like QSGGeometryNode look correct. Could someone tell me what is the problem? Can I switch off scaling for just one particular QQuickItem? If no, what should I set to render it correctly?

    Also, when I try to set opacity on QQuickItem with a lot of QSGOpacityNodes in scene graph node tree I get segmentation fault. What can cause this?

    Regards, Artem

    raven-worxR 1 Reply Last reply
    0
    • P polaris

      Hello,

      I use QtQuickControls 2 together with QQuickItem-derived class in my app. After I set AA_EnableHighDpiScaling attribute and all QQuickControls 2 components look correctly on my smartphone but object of my custom class is scaled incorrectly. Here is the app without HighDpi scaling with minimum zoom(the way it is meant to work):

      http://pasteboard.co/6dmRQpVaZ.png

      And here is the one with scaling with minimum zoom:

      http://pasteboard.co/CxdoQ7rr.png

      It seems that on the second screen the object is scaled too much and I can see square pixels of all textures that I draw with QPixmap or QImage. However, the images that I load from external memory and nodes like QSGGeometryNode look correct. Could someone tell me what is the problem? Can I switch off scaling for just one particular QQuickItem? If no, what should I set to render it correctly?

      Also, when I try to set opacity on QQuickItem with a lot of QSGOpacityNodes in scene graph node tree I get segmentation fault. What can cause this?

      Regards, Artem

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @polaris
      did you read this?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      P 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @polaris
        did you read this?

        P Offline
        P Offline
        polaris
        wrote on last edited by
        #3

        @raven-worx Thank you for your reply. I solved the problem by dividing QSGTexture's size by the QQuickWindow::effectiveDevicePixelRatio()

        I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?

        Personally I'm upset with the way high dpi scaling works. Qt documentation suggests to use prescaled images for each dpi but why there is no way to tell that Image is already scaled?

        raven-worxR 1 Reply Last reply
        0
        • P polaris

          @raven-worx Thank you for your reply. I solved the problem by dividing QSGTexture's size by the QQuickWindow::effectiveDevicePixelRatio()

          I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?

          Personally I'm upset with the way high dpi scaling works. Qt documentation suggests to use prescaled images for each dpi but why there is no way to tell that Image is already scaled?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @polaris said:

          I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?

          Using the Screen type. Also you may want to read this

          Image {
              source: {
                  if (Screen.PixelDensity < 40)
                  "image_low_dpi.png"
                  else if (Screen.PixelDensity > 300)
                  "image_high_dpi.png"
                  else
                  "image.png"
                  }
              }
          

          alternatively you can implement such smart behavior hidden within a custom QQuickImageProvider

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          P 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @polaris said:

            I have another problem now. I use prescaled bitmap images for different dpi. However, when I set AA_EnableHighDpiScaling attribute images in QML are scaled more than I need. I tried to use @2x prefix but it doesn't work on Android (it is Apple specific). Is there a better solution than always dividing the size of image by pixel ratio?

            Using the Screen type. Also you may want to read this

            Image {
                source: {
                    if (Screen.PixelDensity < 40)
                    "image_low_dpi.png"
                    else if (Screen.PixelDensity > 300)
                    "image_high_dpi.png"
                    else
                    "image.png"
                    }
                }
            

            alternatively you can implement such smart behavior hidden within a custom QQuickImageProvider

            P Offline
            P Offline
            polaris
            wrote on last edited by
            #5

            @raven-worx I'm doing exactly the same thing as in your code. However, Qt scales all types of images regardless of their resolution when I switch on high dpi scaling. To cancel this scaling I have to divide width and height of Image by Screen.pixelRatio. I wonder, how can I specify that this Image is already scaled to specific dpi and disable standard high dpi scaling for this Image?
            In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android?

            jpnurmiJ 1 Reply Last reply
            0
            • P polaris

              @raven-worx I'm doing exactly the same thing as in your code. However, Qt scales all types of images regardless of their resolution when I switch on high dpi scaling. To cancel this scaling I have to divide width and height of Image by Screen.pixelRatio. I wonder, how can I specify that this Image is already scaled to specific dpi and disable standard high dpi scaling for this Image?
              In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android?

              jpnurmiJ Offline
              jpnurmiJ Offline
              jpnurmi
              wrote on last edited by
              #6

              @polaris said:

              In Qt Quick Controls 2.0 Gallery example @2x like suffixes are used for higher dpi versions of images. Does this technique work on Android?

              Yes, Qt has fully cross-platform high DPI support since version 5.6. Notice that if you are reading images from disk with QPixmap or QImage, they do not select @Nx high DPI versions. You can use QIcon (or at your own risk, undocumented qt_findAtNxFile() declared in qicon.h) to load high DPI versions.

              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