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

Broken window state after closing a top-level widget

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • 5.12.5
    • 5.12.4
    • None
    • Windows 10
    • Windows
    • deac052a40c93633041da058d5c73c9e91aa76c7

    Description

      The attached project demonstrates an issue where top-level widgets appear blank after being minimized and restored. I tested this with Qt 5.12.4 on Windows using the MSVC2015 compiler.

      EDIT: This issue does no longer occurs with Qt 5.13.0

      In the code below, we create a QMainWindow with a button that shows another top-level widget. After pressing the button for the first time, the window frame of the top-level-widget behaves as expected. It can be minimized and restored.

      However, if you:

      1. close the top-level widget,
      2. press the button to open the top-level widget again,
      3. minimize the top-level widget,
      4. and restore it from the Windows taskbar,

      the widget appears blank:

      Only after using the maximize/restore buttons or manually resizing the window, the window content reappears.

       

      Test code:

      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
      
      	QMainWindow w;
      	w.setWindowTitle("Main Window");
      
      	// setup a top-level widget
      	QWidget topLevelWidget;
      	{
      		QVBoxLayout *const topLevelWidgetLayout = new QVBoxLayout(&topLevelWidget);
      		QLabel *const testLabel = new QLabel(&topLevelWidget);
      
      		testLabel->setText("Is this text visible?");
      		testLabel->setStyleSheet("background-color: #00FFFF;");
      		testLabel->setMinimumSize(200, 200);
      
      		topLevelWidget.setLayout(topLevelWidgetLayout);
      		topLevelWidgetLayout->addWidget(testLabel);
      	}
      
      	// setup button that shows the top level window
      	QPushButton *const openCustomWidgetButton = new QPushButton;
      	{
      		openCustomWidgetButton->setText("Open Second Window");
      		QObject::connect(openCustomWidgetButton, &QPushButton::clicked, [&topLevelWidget]()
      		{
      			if (topLevelWidget.isVisible())
      				return;
      
      			qDebug() << "showing top-level widget";
      
      			topLevelWidget.showNormal();
      			topLevelWidget.activateWindow();
      			topLevelWidget.raise();
      		});
      	}
      
      	w.setCentralWidget(openCustomWidgetButton);
      	w.show();
      
      	return a.exec();
      }
      

      Attachments

        Issue Links

          Activity

            People

              anrocha André De La Rocha (Inactive)
              as Andreas Strunski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: