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
    {
        Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent = 0) : QMainWindow(parent), ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            QTimer::singleShot(2000, this, &MainWindow::showChildWindow);
        }
    
        ~MainWindow()
        {
            delete ui;
        }
    private:
        Ui::MainWindow *ui;
    
        void showChildWindow()
        {
            QErrorMessage* err{new QErrorMessage{this}};
            err->setWindowModality(Qt::ApplicationModal);
            err->showMessage("Test");
            err->setGeometry(100, 100, 300, 300);
            err->exec();
        }
    };
    
    #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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.