Quote Originally Posted by codeslicer View Post
What I did was override the keyPressEvent:

Qt Code:
  1. void myClass::keyPressEvent(QKeyEvent* event) {
  2. if (event->key() != Qt::Key_Escape) {
  3. QDialog::keyPressEvent(event);
  4. }
  5. else {
  6. close();
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 

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.