QDialog modal issue



  • Hello,

    i have a problem getting my QDialogs modal.

    What happens is, that I show my QDialogs with exec() which should make them modal (tried using setModal and show() before either). It works... for QDialogs which I start from dialogs or widget within my QMainWindow. But I have to start some QDialog directly from QMainWindow, so their QActions to open them is directly on the QMainWindow.
    And here comes in a strange behaviour (at least from my perspective). When I open a QDialog from QMainWindow with exec() it is noch modal for the first time. Closing this and then opening the same or another QDialog, these dialogs are modal. So this only happens the first time.

    What may be the reason for this behaviour? Is there any event that has to be triggered before I can add the first QDialogs to my QMainWindow? Or something else? Unfortunately i can't post any code, so this will be a little guessing around and collecting ideas.

    The program runs on Linux.

    Regards
    Henning Lange



  • I just realized that this has nothing to do with the first or second time.

    It is related to clicking into the QMainWindow before openen a QDialog.

    So it seems the QMainWindow has to be the active window before calling a QDialog.

    But how can i achieve this programmatically? I tried work-around with mainwindow.setFocus and sending a QMouseEvent to the MainWindow. Both doesn't work.

    Can someone give me an idea of how to simulate a mouse-click properly?

    This is how i try it right now, but it doesn't work:

    @ QPoint pos(1,1);
    QMouseEvent event(QEvent::MouseButtonPress, pos, Qt::LeftButton, 0, 0);
    app.sendEvent(&mainframe, &event);@

    Another thing i inspected: When i calll the dialog without clicking into the mainwindow first, then the dialog has all 3 buttons in the title bar. When i click into mainwindow first, then the dialog has only the close button.

    I hope someone can give me insight to this behaviour.

    Thanks in advance
    Henning Lange



  • Okay... another reply.

    Investigating this problem further i found out the the call on
    @myMainWindow.showFullScreen();@
    is the problem. If I call
    @myMainWindow.showMaximized();@
    the problem does not occur so i guess this issue is related to the X-Window-System.

    Is here anybody who can assist me with this problem? It's pretty tough for me to solve this using showFullScreen().

    In hope for a helping hand
    Henning Lange



  • Hi, I had a similar problem, and i have solved it by calling show() instead of exec().
    Hope it helps you.

    mydialog.setModal(true);
    mydialog.show();


Log in to reply
 

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