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

QMainWindow mistakenly reports itself as active when it is not

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.8.1
    • Widgets: Main Window
    • None
    • Windows

    Description

      See minimal reproducible example below.

      Steps to reproduce:
      1. Compile the example.
      2. Launch the example AND IMMEDIATELY switch to another app/window before example main window is created and displayed.

      This way the example main windows does not receive focus and is started on background.

      Now, somehow observer the debug CLI output and it is reporting this:

      true
      QWidget(0x0)
      

      So the ` isActiveWindow()` reports true, even if the window is covered by other apps/windows and does not have any kind of focus.

      If you then alt+tab into the example window and alt+tab again out of it, the output fixes itself and displays correct `false` value (not active window).

      #include "mainwindow.h"
      #include "./ui_mainwindow.h"
      
      #include <QApplication>
      #include <QTimer>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent), ui(new Ui::MainWindow) {
        ui->setupUi(this);
      
        QTimer *tmr = new QTimer(this);
      
        tmr->start(1000);
      
        connect(tmr, &QTimer::timeout, this, [=]() {
          qDebug() << isActiveWindow();
          qDebug() << QApplication::activeModalWidget();
        });
      }
      
      MainWindow::~MainWindow() { delete ui; }
      
      

      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
            skunkos Martin Rotter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes