Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-131472

BorderImage display error if change the window DPR

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8
    • None
    • Linux/Wayland

    Description

      When using `QQuickImageProvider` to provide resources for `BorderImage`, there is an issue with how it handles window scaling. If the screen's scaling factor is dynamically adjusted at runtime, `BorderImage` will use the window's `devicePixelRatio` as the `devicePixelRatio` for the image resource, which is incorrect. This issue can be resolved by forcing the image resource to reload—for example, by setting the `source` property to an empty string and then restoring it to its original value. This will reset the image resource's `devicePixelRatio` to 1.0, which is the correct value. Alternatively, restarting the application after changing the screen's scaling factor can also solve the problem.

      When loading image resources directly using `qrc` file paths, the issue does not occur, and the image resource's `devicePixelRatio` is always 1.0.

      I have only tested `BorderImage`, but since the behavior of setting `devicePixelRatio` occurs in `QQuickImageBase`, I am unsure if `Image` or `AnimatedImage` have the same issue.

      In various `Image` components in QML, scaling-related issues are commonly encountered when attempting to display image resources correctly under screen scaling factors greater than 1.0 (in HiDPI scenarios). However, the `devicePixelRatio` of the image resource is not exposed as a property in `Image`. Instead, it is automatically calculated in `QQuickImageBase` and related `QQuickPixmap` image-loading processes. The Qt code even includes checks for whether the image format is SVG or PDF, but I believe this is not a good design. Such decisions should be left to the developers.

      BorderImage-BUG.zip

       

      I marked the reproduction platform as Linux/Wayland because it is the only testing environment I have. However, based on the nature of this bug, it should occur on any platform. It's just that users rarely change the screen's scaling factor at runtime.

      The reproduction steps are straightforward: in any Wayland environment, first set the screen scaling factor to 1.0 and then launch the test application. Next, change the screen's scaling factor to 2.0, and the bug should appear.

      Attachments

        1. BorderImage-BUG.zip
          9 kB
        2. start-with-dpr-1.png
          start-with-dpr-1.png
          28 kB
        3. dpr1-to-dpr2.png
          dpr1-to-dpr2.png
          66 kB
        4. start-with-dpr2.png
          start-with-dpr2.png
          64 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-131472
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              zccrs JiDe Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews