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

Maximizing and restoring a window gradually moves it downwards

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.8.1, 6.9.0 FF
    • 6.5.2, 6.6, 6.7, 6.8
    • QPA: Windows
    • None
    • Windows 10, Qt ^6.5.2
    • Windows
    • 06fcb3dfe (dev), 5abc6e9cc (6.8)

    Description

      From Qt 6.5.2 onwards, maximizing and restoring a window moves it downwards (e.g. by pressing WIN + up/down). Doing that repeatedly will cause it to end up at the bottom of the screen.
      This doesn't occur on 6.5.0. In 6.5.1 this doesn't happen either, but after maximizing and restoring the window for the first time, it doesn't shrink to the correct size, but remains at that size.

      Example app:

      #include <QApplication>
      #include <QLabel>
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
        QLabel foo("Foo");
        foo.show();
      
        return app.exec();
      }
      

      This might be similar to QTBUG-124250 (i.e. something related to the window frame margins). Seems like it's 21e411687428d05655b8db2634466384fa35cc03 from QTBUG-112814.

      The issue is (most likely) that the restoreGeometry is translated by the windowPlacementOffset (as a result of calling normalFrameGeometry), but it's not translated back when calling SetWindowPlacement (it's going from GetWindowPlacement -> translate -> SetWindowPlacement). The following patch resolved the issue for me. If that change looks reviewable, I can open a change on Gerrit.

      diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp
      index e1b9cfdcda..572bcd3d1d 100644
      --- a/src/plugins/platforms/windows/qwindowswindow.cpp
      +++ b/src/plugins/platforms/windows/qwindowswindow.cpp
      @@ -2076,6 +2076,16 @@ static QRect normalFrameGeometry(HWND hwnd)
           return QRect();
       }
       
      +static QRect normalFrameGeometryUntranslated(HWND hwnd)
      +{
      +    WINDOWPLACEMENT wp;
      +    wp.length = sizeof(WINDOWPLACEMENT);
      +    if (GetWindowPlacement(hwnd, &wp)) {
      +        return qrectFromRECT(wp.rcNormalPosition);
      +    }
      +    return QRect();
      +}
      +
       QRect QWindowsWindow::normalGeometry() const
       {
           // Check for fake 'fullscreen' mode.
      @@ -2529,7 +2539,7 @@ void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state)
       
       void QWindowsWindow::updateRestoreGeometry()
       {
      -    m_data.restoreGeometry = normalFrameGeometry(m_data.hwnd);
      +    m_data.restoreGeometry = normalFrameGeometryUntranslated(m_data.hwnd);
       }
       
       void QWindowsWindow::setWindowState(Qt::WindowStates state)
      

      Attachments

        Issue Links

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

          Activity

            People

              axelspoerl Axel Spoerl
              nerixyz Tom Fors
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews