QDialogs, closeEvent() and the Escape Key



  • The "documentation here":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key leads me to believe that when I press the Escape Key (when a Dialog is open and focused), that it should trigger the "QDialog::closeEvent()" function. The only problem is that it's not. Am I misinterpreting something here?

    I want my users to be able to close the Dialog with a press of the ESC Key, but because "closeEvent()" is not triggered, it doesn't return a result from the "QDialog::exec()" method.

    Also, is there a way that I close the dialog window from the constructor? These dialogs are also supposed to be singletons.



  • As far as I understand documentation this is only related to modeless dialog.
    Calling exec() means it is modal.

    Regards,
    Alex


  • Moderators

    [quote author="cuddlykittens11" date="1421968886"]The "documentation here":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key leads me to believe that when I press the Escape Key (when a Dialog is open and focused), that it should trigger the "QDialog::closeEvent()" function. The only problem is that it's not. Am I misinterpreting something here?

    I want my users to be able to close the Dialog with a press of the ESC Key, but because "closeEvent()" is not triggered, it doesn't return a result from the "QDialog::exec()" method.
    [/quote]

    It may be that there is a shortcut conflict with the Escape key? What are the content widgets of your dialog? Are you using the Esc key as a shortcut there?

    [quote author="cuddlykittens11" date="1421968886"]
    Also, is there a way that I close the dialog window from the constructor? These dialogs are also supposed to be singletons.[/quote]

    i don't quite understand what you are trying to do? You are calling QDialog::exec() out of a constructor? If so you shouldn't do that.

    [quote author="alex_malyu" date="1421983656"]As far as I understand documentation this is only related to modeless dialog.
    Calling exec() means it is modal.[/quote]

    i would say it's the other way around



  • [quote author="cuddlykittens11" date="1421968886"]it doesn't return a result from the "QDialog::exec()" method.[/quote]

    You are wrong here. QDialog::Rejected is returned if Esc key is pressed.

    [quote author="cuddlykittens11" date="1421968886"]
    Also, is there a way that I close the dialog window from the constructor? [/quote]

    Yes:
    @
    QTimer::singleShot(0, this, [=](){ reject(); })
    @



  • Okay, I cleaned up my dialog issues. Thanks for the help!


Log in to reply
 

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