Re: QDialog and closeEvent
override reject()
if you close a dialog with ESC, X window button or alt+f4 goes to reject()
Re: QDialog and closeEvent
Quote:
Originally Posted by
javimoya
override reject()
if you close a dialog with ESC, X window button or alt+f4 goes to reject()
Thanks.
By the way, should I do something like this:
Code:
void CDialogLevelProperties::reject() {
// some code before canceling this dialog
// bla bla bla
}
Re: QDialog and closeEvent
ya ... this should work..
Re: QDialog and closeEvent
What I did was override the keyPressEvent:
Code:
void myClass
::keyPressEvent(QKeyEvent* event
) { if (event->key() != Qt::Key_Escape) {
}
else {
close();
}
}
Then this fires the closeEvent() which you can then work with there. But perhaps the above solution is easier.
Re: QDialog and closeEvent
Quote:
Originally Posted by
codeslicer
What I did was override the keyPressEvent:
Code:
void myClass
::keyPressEvent(QKeyEvent* event
) { if (event->key() != Qt::Key_Escape) {
}
else {
close();
}
}
Then this fires the closeEvent() which you can then work with there. But perhaps the above solution is easier.
Actually that was my former solution. That code does not work when user press X button. javimoya solution is better. Anyway, thanks.
Re: QDialog and closeEvent
Quote:
Originally Posted by
ricardo
Actually that was my former solution. That code does not work when user press X button. javimoya solution is better. Anyway, thanks.
you have to accept the event and this will work
Code:
void myClass
::keyPressEvent(QKeyEvent* event
) {
if (event->key() != Qt::Key_Escape)
{
}
else
{
event->accept();//Bye Bye event
close();
}
}