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

Title bar cannot be restored after using QWidget::setGeometry

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.1
    • None
    • Windows 11
    • Windows

    Description

      When a window is in fullscreen mode and setGeometry is called, it loses the ability to restore the title bar.

      I've only tested on Windows.

      From the debugging I've done, it seems like the issue is caused by setGeometry changing the window state, but not calling SetWindowPos to refresh the style. Then, when calling showNormal after setGeometry, the state (and therefore the style) is not updated because the widget thinks it's still in the same state and early returns.

       

      Noteworthy functions:

      QWidgetPrivate::setGeometry_sys
      QWindowsBaseWindow::setGeometry_sys
      QWindowsWindow::setWindowState_sys
      

       

      Code to reproduce: 

      QApplication application(argc, argv);	
      QMainWindow window;
      
      window.showFullScreen();
      
      // Commenting the following line prevents the bug from happening 
      // Can also be move or resize, they have the same behavior 
      window.setGeometry(100, 50, 500, 500);
      
      window.showNormal();
      
      application.exec();  

       

      The issue can be worked around by using the following code instead of showNormal:

      HWND hwnd = reinterpret_cast<HWND>(window.winId());
      
      LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
      		
      style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SIZEBOX | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;	
      	
      SetWindowLongPtr(hwnd, GWL_STYLE, style);
      		
      SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); 
      
      window.show();

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            felixsoftdrive Félix Lamontagne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes