Qt minimizing Dialog minimizes Parent Window



  • In my application I have a parent window and over it a child dialog, when I minimize my child dialog parent window also get minimized, how can I avoid it. The child dialog is sub-classed from QDialog

    And the child dialog pop-up is executed in this way,

    ChildDilago PopUp;
    PopUp.setModal(false);
    Qt::WindowFlags flags = Qt::Window | Qt::WindowSystemMenuHint
                                | Qt::WindowMinimizeButtonHint
                                | Qt::WindowCloseButtonHint;
    PopUp.setWindowFlags(flags);
    PopUp.setUI(data);
    PopUp.exec();
    

    What can be the issue here?, any help will be appreciated...

    Thanks
    Haris


  • Moderators

    There are two things here that mix into the issue:

    First, as described in the docs, exec() always shows the dialog as modal and ignores anything you set with setModal().

    Second, the Qt::Window flag makes the widget a normal window, so when it is shown modally it is treated as main app window and thus minimizing it minimizes whole app.

    One thing you can do is remove the call to setModal(false), as it does nothing anyway, and change your flags to contain Qt::Dialog instead of Qt::Window. The dialog will now be (well, obviously) a dialog and not minimize the whole app. The downside is that, since it is modal, the OS will send the main window to the back, as there is no interaction with it possible anyway.

    If you want a proper, non-modal dialog that can be minimized independently of your main window you can do it like this:

            ChildDilago * PopUp = new ChildDilago (this); //so that it won't go out of scope and be destroyed, modality is false by default
            PopUp->setAttribute(Qt::WA_DeleteOnClose, true); //so that it will be deleted when closed
            Qt::WindowFlags flags = Qt::Dialog | Qt::WindowSystemMenuHint
                                        | Qt::WindowMinimizeButtonHint
                                        | Qt::WindowCloseButtonHint;
            PopUp->setWindowFlags(flags); //so that it has min/max frame buttons
            PopUp->setUI(data);
            PopUp->show(); // so that it is shown not modally
    


  • Hi Thanks for the detailed answer, now the issue solved


Log in to reply
 

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