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

Drastic resizing and repositioning when moving a QWidget between different DPIs

    XMLWordPrintable

Details

    Description

      Reproducer attached. My setup is a 4K@150% and a 1080p@100%. The reproducer features a top-level QWidget that has a minimal size. A layout is set, and the layout is controlling another QWidget which sets setHeightForWidth to true.

      The issue is that at the moment of moving window from 1080p screen (higher DPI) to 4K screen (lower DPI), widget is resized to 1/4 of its original size (maybe not necessarily 1/4 if DPIs are different from mine) and moved to a nonsense far position (usually a few hundreds of pixels apart between 2 consecutive moveEvent). This is confirmed by overriding resize and move event.

      Nevertheless, the drastic changes are not necessarily visual but rather feels like internal geometry calculation glitch of Qt. In most cases, transition between screens is smooth and hardly anything strange can be noticed. Not until the top-level QWidget is already close to its minimal size. One can resize the top-level QWidget to its minimal size before dragging it to another screen. Then at the moment of crossing, widget is resized beyond its minimal size. And then the drastic moving is visible too. Top-level QWidget suddenly jumps to a nonsense far position.

      The solution can be either:
      1. Comment out QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      2. Comment out setMinimumSize(QSize(200, 120));
      3. Comment out sizePolicy.setHeightForWidth(true);
      4. Do not let inner QWidget sits in a layout.
      Nevertheless, I am not yet able to identify the actual reason. The top-level widget has a minimal size. The inner widget has a preferred height for width and is also controlled by a layout. Definitely some resizing processes are conflicting each other.

      But the problem is gone in Qt6. Both numbers and actual behavior are normal. I don't know how it is solved but it's better to backport.

      Attachments

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

        Activity

          People

            kleint Friedemann Kleint
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes