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

QWidget::restoreGeometry doesn't restore correct screen number if application was in maximized or fullScreen state

    XMLWordPrintable

Details

    • Fix normal geometry on Windows: b9fe8e30cbd7564d9610e097e219212663e42165 (dev, 7.2.2014, 5.3) Fix restore to maximized in Qt 5 ae4243df1e53b0aaeada708f6fa7979a0f0d216a (dev 12.2.2014, 5.3), Qt 4.8.6: d38ae7ea322bedb16045d0dc4a71498fadfb2dd9 (14.3.2014)

    Description

      QWidget::restoreGeometry always shows application window on primary screen if it was in maximized or fullScreen state before calling QWidget::saveGeometry. I have to write something like this to restore my application in fullScreen state on non-primary screens:

      QSettings settings;
      restoreGeometry(settings.value("mainWindowGeometry").toByteArray());
      // Application is on primary screen
      
      if ( isFullScreen() ) {
          showNormal();
          showFullScreen();
          // Application is on another screen, where is was before calling QWidget::saveGeometry
      };
      

      Update 2017-02-14:
      Same thing with window moving (win32-msvc2013, Qt-5.8.0).

      /*	I want to move a window from screen 0 to screen 1 in fullscreen state,
      	screen 0 has different resolution than screen 1.
      */
      void CMyWindow::moveToScreen(int screen) {
      	// window is on screen 0 in fullscreen state
      	// screen == 1
      
      	QDesktopWidget desktop;
      	if (desktop.screenCount() <= screen) return;
      	// screenCount returns 2
      
      	QRect screenGeometry = desktop.availableGeometry(screen);
      	bool fullScreen = this->isFullScreen();
      	bool maximized = this->isMaximized();
      	// screenGeometry is corrent
      	// fullScreen == true
      
      	if (fullScreen || maximized) this->showNormal();
      	// window is on screen 0 in normal state
      
      	QRect geometry = this->geometry();
      	geometry.moveCenter(screenGeometry.center());
      	this->setGeometry(geometry);
      	// window is on screen 1 in normal state
      
      	if (fullScreen) this->showFullScreen();
      	if (maximized) this->showMaximized();
      	// Window is on screen 0 in fullscreen state.
      	// BUG, it must be on screen 1, but it is on screen 0 somehow.
      
      	// bug walkaround
      	if (fullScreen) {
      		this->showNormal();
      		this->showFullScreen();
      	};
      	// window is on screen 1 in fullscreen state
      };

      Attachments

        1. 2017-02-14 QtGeometryBug.zip
          11 kB
        2. qtbug21371.zip
          3 kB
        3. untitled.7z
          0.7 kB

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              moneyiac Mike
              Votes:
              24 Vote for this issue
              Watchers:
              24 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes