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

QWidget::restoreGeometry() breaks when monitors are added/removed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.15.0
    • Widgets: Main Window
    • None
    • Arch Linux, Qt 5.15.0
    • Linux/X11

      If a second monitor is added or removed before starting a Qt application (e.g. when a laptop is docked or undocked), QWidget::restoreGeometry() no longer restores the size of the application on startup. The behavior is reproducible with Qt 5 applications such as KeePassXC and Audacious.

      I believe the culprit is this code:

          // Sanity check bailing out when large variations of screen sizes occur due to
          // high DPI scaling or different levels of DPI awareness.
          if (restoredScreenWidth) {
              const qreal factor = qreal(restoredScreenWidth) / screenWidthF;
              if (factor < 0.8 || factor > 1.25)
                  return false;
      

      Note that restoredScreenWidth is actually the total desktop width (all monitors). It does not seem like a good idea to assume that DPI has changed every time the desktop width changes, since the width can change for other reasons as well.

        1. geometry.cc
          0.5 kB
          John Lindgren
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            john.lindgren@aol.com John Lindgren
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes