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

Windows: QWindow.setTransientParent() sometimes doesn't work when passing a foreign Window constructed using QWindow::fromWinId()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.7.0
    • None
    • Windows 8.1, Windows 10, Qt 5.7.0

    Description

      A transient parent sometimes doesn't change in QWindow (approximately 20% of launches, only in the release version).
      QWindow.transientParent() returns correct result, but Spy++ shows what 'Parent Window Handle' and 'Owner Window Handle' are 'None'.
      As a result, our window doesn't overlap window which we try to set as transient parent (see screenshot1.png, normal case - screenshot2.png).

      There is next code in sources QWindow::setVisible:

      qt\qtbase\src\gui\kernel\qwindow.cpp:512
      if (type() == Qt::Window) {
          QGuiApplicationPrivate *app_priv = QGuiApplicationPrivate::instance();
          QString &firstWindowTitle = app_priv->firstWindowTitle;
          if (!firstWindowTitle.isEmpty()) {
              setTitle(firstWindowTitle);
              firstWindowTitle = QString();
          }
          if (!app_priv->forcedWindowIcon.isNull())
              setIcon(app_priv->forcedWindowIcon);
      
          // Handling of the -qwindowgeometry, -geometry command line arguments
          static bool geometryApplied = false;
          if (!geometryApplied) {
              geometryApplied = true;
              QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(this);
          }
      }
      

      Possible the issue related with this code, because when we set flag Qt::Tool for QWindow - issue doesn't reproduces.

      Steps to reproduce:
      1. Replace 'parentWId' to the appropriate WId which you would like to set as transient parent in code which is given below.
      2. Build release.
      3. Run application. If the issue didn't reproduce - relaunch it.

      main.cpp
      #include <QApplication>
      #include <QWindow>
      
      int main(int argc, char *argv[])
      {
        QApplication a(argc, argv);
      
        auto parentWId = 12345678; //Replace to the appropriate WId
        auto transientParent = QWindow::fromWinId(static_cast<WId>( parentWId ));
      
        QWindow window;
        window.resize(400, 200);
        window.setTransientParent( transientParent );
        window.show();
      
        return a.exec();
      }
      

      Attachments

        1. qtbug55669.zip
          1 kB
        2. screenshot1.png
          screenshot1.png
          80 kB
        3. screenshot2 .png
          screenshot2 .png
          95 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            airslax airslax
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes