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

restoreGeometry() to maximized MainWindow results in wrong geometry() returned between show() and exec()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P2: Important
    • None
    • 5.15.6
    • Widgets: Main Window
    • None
    • Windows

    Description

      I'm getting a couple bugs since my port from Qt4 to Qt5.

      • I'm positioning dialog popup relative to MainWindow::pos() and noticed the dialog position is wrong when displayed after MainWindow::show() but before exec()
      • When restoring MainWindow to a maximized state (with saveGeometry, saveState/restoreGeometry, restoreState) I get occasional windows that are in windowed mode, at a wrong position, but in a maximized state.
      Origin

      I narrowed these bugs to the same root cause in Widget::restoreGeometry()
      https://codereview.qt-project.org/gitweb?p=qt/qtbase.git;a=blob;f=src/widgets/kernel/qwidget.cpp;h=fa6915e545555ac0e5e1ebf001171e36814e8ee7;hb=HEAD#l7484

      Although restoring window to a maximized state, the setGeometry() call is passed the QRect from the normal state

      setGeometry(restoredNormalGeometry);
      

      The setWindowState call a few lines later is in charge of applying the maximized state, however this will not update the internal crect to the maximized value.

      setWindowState(ws);
      d_func()->topData()->normalGeometry = restoredNormalGeometry;
      
      Proposed fix

      https://codereview.qt-project.org/c/qt/qtbase/+/433373
      Patch is attached, it consists in adding 2 lines to set the crect, similar to how it is done in setGeometry()

      if (testAttribute(Qt::WA_WState_Created)) {
          data->crect.setTopLeft(restoredGeometry.topLeft());
          data->crect.setSize(restoredGeometry.size().boundedTo(maximumSize()).expandedTo(minimumSize()));
      }
      

      Looking forward hearing your feedback

      Attachments

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

        Activity

          People

            axelspoerl Axel Spoerl
            julienmaille Julien Maille
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d

                Gerrit Reviews

                  There are no open Gerrit changes