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

Backport fix for mixed-DPI window calculations

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.6
    • GUI: High-DPI
    • Windows 10 Pro 21H2, MSVC 2019 x64

    Description

      There is a bug in Qt 6.3.2 and QT 6.2.6 where windows can be shown with wrong size calculations. This bug is not present in Qt 6.4.0; it would be great to backport the fix to Qt 6.2 LTS.

       

      Code

      // main.qml
      import QtQuick.Controls.Material
      
      ApplicationWindow {
          width: 640
          height: 480
          visible: true
      
          ConfigurationWindow { id: config }
      
          Button {
              text: "Pop Up"
              onClicked: config.show()
          }
      }
      
      // ConfigurationWindow.qml
      import QtQuick.Controls.Material
      
      ApplicationWindow {
          id: popup
          width: 360
          height: 240
      /*
          // WORKAROUND: "Overriding" Window.show() like this forces the correct calculations
          function show() {
              popup.visible = true
              popup.width += 1
              popup.width -= 1
          }
      */
          Button {
              text: "I am right-aligned"
              anchors.right: parent.right
          }
      
          onVisibleChanged: {
              if (popup.visible)
                  console.log("Popup size:", popup.width, 'x', popup.height)
          }
      }
      

       

      Steps to reproduce

      1. Set up 2 screens, where the primary screen has 125% scaling and the secondary screen has 100% scaling
      2. Build and run the attached project
      3. Drag the main window to the secondary screen
      4. Click "Pop Up"
      5. Close the popup window
      6. Click "Pop Up" again

       

      Outcomes for Qt 6.2/6.3 (wrong)

      Console output:

      qml: Popup size: 360 x 240
      qml: Popup size: 288 x 192
      

       

      The pop-up window looks like right-align-wrong1.png the first time, then r_ight-align-wrong2.png_ the second time.

       

      Outcomes for Qt 6.4 (correct)

      Console output:

      qml: Popup size: 360 x 240
      qml: Popup size: 360 x 240
      

      The pop-up window looks like right-align-correct.png both times.

       

      Workaround

      After show()-ing the popup window, increment then decrement the window width. This seems to force the correct calculations.

      Attachments

        1. qtbug107882.zip
          1 kB
          Sze Howe Koh
        2. right-align-correct.png
          8 kB
          Sze Howe Koh
        3. right-align-wrong1.png
          8 kB
          Sze Howe Koh
        4. right-align-wrong2.png
          8 kB
          Sze Howe Koh

        Activity

          People

            sorvig Morten Sørvig
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: