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

Bad geometry for widgets created with QWidget::createWindowContainer(QWindow::fromWinId())

    XMLWordPrintable

Details

    Description

      My app is composed of two processes a master and a slave. The slave is created by the master using QProcess. The master is attaching the slave window by using QWindow::fromWinId() and QWidget::createWindowContainer().

      The bug is that the geometry of the slave is totally wrong: it is not expanding to the whole allocated space in the master window.

      The really strange behavior is that if we open a dialog from the slave and then we resize the window then the issue is fixed! Below is a simple code snippet to reproduce the issue.

      main.cpp
      #include <QProcess>
      #include <QVBoxLayout>
      #include <QLabel>
      #include <QMessageBox>
      #include <QTextStream>
      #include <QToolButton>
      #include <QWindow>
      
      int main(int argc, char** argv)
      {
          QApplication qapp(argc, argv);
      
          if (qapp.arguments().contains("--slave")) {
              QWidget     slaveWindow;
              QVBoxLayout layout(&slaveWindow);
              QToolButton button;
      
              button.setText("Click Me");
              button.connect(&button, &QToolButton::clicked, [&slaveWindow]() {
                  QMessageBox::information(&slaveWindow, "Close Me", "Resize the mainWindow once this dialog is closed.", QMessageBox::Ok);
              });
              layout.addWidget(new QLabel("slaveWindow", &slaveWindow));
              layout.addWidget(&button);
              slaveWindow.setStyleSheet("background: red;");
              slaveWindow.show();
      
              QTextStream ostream(stdout);
              ostream << slaveWindow.winId();
              ostream.flush();
      
              return qapp.exec();
          } else {
              QWidget     mainWindow;
              QVBoxLayout layout(&mainWindow);
              QProcess    process;
              WId         processWid;
      
              process.start(qapp.applicationFilePath(), {"--slave"});
              process.waitForReadyRead();
              processWid = process.readAll().toUInt();
      
              QWindow* window = QWindow::fromWinId(processWid);
              QWidget* widget = QWidget::createWindowContainer(window);
              layout.addWidget(new QLabel("mainWindow", &mainWindow));
              layout.addWidget(widget);
              mainWindow.setStyleSheet("background: green;");
              mainWindow.resize(400, 400);
              mainWindow.show();
      
              return qapp.exec();
          }
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              francoisct François Colas
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes