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

Problems with fixed size dialogs on multiscreen high DPI

    XMLWordPrintable

Details

    • f1ec81b543fe1d5090acff298e24faf10a7bac63 (qtbase/5.9, 26.9.2017, 5.9.3)

    Description

      The best way to make a dialog (with e.g only labels and buttons) fixed size is

      layout()->setSizeConstraint(QLayout::SetFixedSize);

      However in a multi screen environment moving such a dialog from one screen to another (slowly) in high DPI mode may cause a lot of flickering and the dialog may end up with controls placed completely wrong.

      Steps to reproduce (at least the flickering part)

      • Have two screens with very diffent device pixel ratio (2.0 vs 1.0). In my example I have two 4k screens with one set to 175 and the other to 125. (Monitor 1 (scale 125) is set to be on the right side)
      • Compile attached example
      • OR modify the example: examples\widgets\mainwindows\mainwindow )

      int main(int argc, char **argv) (main.cpp)

      as the first line of the function (before QApplication ctor) insert

      QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

      and before mainWin.show() add

      mainWin.layout()->setSizeConstraint(QLayout::SetFixedSize);
      // Somewhere add #include <QLayout>
      • Finally slowly move the dialog from one screen to the other. (On faster moves the risk of any flicking (and dialog mess) is reduced)

      Reason:
      When the dialog moves to a new screen (in high DPI mode) Qt tries to change the window size in QGuiApplicationPrivate::processGeometryChangeEvent. However the size constraint will ensure that the dialog quickly afterwards will resize again. This new (layout constaint) size often causes the to end up being mainly on the previous Screen, so the dialog is nearly instantly moved backed to the screen it came from. Here it is again resized (twice). This will again cause the dialog end up on the screen Qt originally tried to change to.
      Only a top left point check (which seems to be held on most or all resizes) prevents infinite screen changes, but a new small mouse movement will instantly repeat this resize the circus.

      Somehow all these size changes can cause the controls to be completely wrong. (Though other examples may reproduce better than this mainwindow example)

      This issue can be reproduced on Windows and may exist on Linux (not tested). It does not happen on Mac.

      Attachments

        1. image-2017-09-07-07-39-12-152.png
          image-2017-09-07-07-39-12-152.png
          175 kB
        2. main.cpp
          0.5 kB
        3. main.pro
          0.0 kB
        4. qtbug62971_diag.diff
          2 kB
        5. qtbug62971_log.txt
          5 kB
        6. qtbug62971.zip
          2 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              tmartsum Thorbjørn Lund Martsum
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: