Please nominate your Qt Champions for 2021!

Weirdest behavior of a modal window when the parent is in move/size loop.

  • Greetings.

    Please take a look at the following code:

    // MainWindow.h
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include "MainWindow.h"
    #include "ui_mainwindow.h"
    #include <QTimer>
    #include <QErrorMessage>
    namespace Ui {
    class MainWindow;
    class MainWindow : public QMainWindow
        explicit MainWindow(QWidget *parent = 0) : QMainWindow(parent), ui(new Ui::MainWindow)
            QTimer::singleShot(2000, this, &MainWindow::showChildWindow);
            delete ui;
        Ui::MainWindow *ui;
        void showChildWindow()
            QErrorMessage* err{new QErrorMessage{this}};
            err->setGeometry(100, 100, 300, 300);
    #endif // MAINWINDOW_H

    At the first look it seems ok. It's even works ok until you try to move/resize it before QErrorMessage appear. If this message was showed during such loop (move/size modal loop) then this message becomes disabled for moving/resizing also. Moreover, after closing it the parent window jumps to the previos position what looks jerky.

  • I tried to do the same with native Windows windows and it looks like that operating system works this way. Native modal windows are also inactive for dragging/resizing if was created during parent move/resize.

Log in to reply