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

QMdiSubWindow disappears after show/hide of QMainWindow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.10.1, 5.12.3
    • Charts
    • None
    • Windows 10 Pro
      Version: 1903
      OS Build: 18362.207
    • Windows

    Description

      Scenario

      QMainWindow with a QMenuBar and a QMdiArea as the central widget. Add a single QMdiSubWindow containing a QChartView. Maximize the QMdiSubWindow and then restore it. Don't move the QMdiSubWindow after this. Now hide the QMainWindow and then call QMainWindow::grab(). Setup a singleshot timer to call QMainWindow::show() (interval can be 0). Once the QMainWindow is shown again, the QMdiSubWindow and it's contents are no longer visible.

      Workaround

      Calling QWidget::repaint() on the QMdiSubWindow restores the window decorations

      Calling QWidget::repaint() on the QChartView's viewport restores QChartView

       

      Code

      // main.cpp
      
      #include <QApplication>
      
      #include <QTimer>
      #include <QMenuBar>
      #include <QMdiArea>
      #include <QMdiSubWindow>
      #include <QMainWindow>
      
      #include <QtCharts/QChartView>
      
      QT_CHARTS_USE_NAMESPACE
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QMainWindow mw;
      
          // Must have QMenuBar to see the problem
          // QMdiSubWindow maximizes differently when the menu bar is present
          mw.setMenuBar(new QMenuBar);
      
          QMdiArea mdi;
          mw.setCentralWidget(&mdi);
      
          // Can only reproduce the issue using a QChartView
          // Even QGraphicsView didn't have the issue.
          // Also, MDI area can only have one subwindow
          QChartView cv;
          QMdiSubWindow *sw = mdi.addSubWindow(&cv);
      
          QTimer::singleShot(1000, sw, &QMdiSubWindow::showMaximized);    // Maximize the SubWindow
          QTimer::singleShot(2000, sw, &QMdiSubWindow::showNormal);       // Take it back to normal
          QTimer::singleShot(3000, &mw, [&mw] {
              mw.hide();                                                  // Hide the MainWindow
              mw.grab();                                                  // This has to be done after hide()
              QTimer::singleShot(0, &mw, &QMainWindow::show);             // Must call show() from the event loop
          });
      
          // Repainting the Window and the viewport of the QChartView causes the window to re-appear
          QTimer::singleShot(5000, sw, SLOT(repaint()));
          QTimer::singleShot(5000, cv.viewport(), SLOT(repaint()));
      
          mw.show();
          return a.exec();
      }
      
      QT       += core gui charts
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = MdiBug
      TEMPLATE = app
      
      CONFIG += c++11
      
      SOURCES += \
              main.cpp
      

      Attachments

        1. main.cpp
          1 kB
        2. MdiBug.pro
          0.2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            e0348803 Miikka Heikkinen
            tim.lassiter Timothy Lassiter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes