[Solved]QDialog::eventFilter() can't Filter
-
Hi all
I want to get rid of QDialog closing when Escape is pressed. So i used eventFilter() like this:
class ChangeMaster : public QDialog { protected: bool eventFilter(QObject *object, QEvent *event) override; .... }
and in the source file
bool ChangeMaster::eventFilter(QObject *object, QEvent *event) { qDebug() << "EventFilter entered"; if(object == this && event->type() == QEvent::KeyPress) { qDebug() << "Event is key press"; QKeyEvent * keyEvent = static_cast<QKeyEvent*>(event); if(keyEvent->key() == Qt::Key_Escape) return true; else return false; } return object->parent()->eventFilter(object, event); }
When i run the program and press ESC, it always closes. Also it seems eventFilter never runs because there is no qDebug printing saying "EventFilter entered".
I couldn't figure out why. Probably because i am not doing everything properly. How can i solve this?
Thanks in advance
-
Hi @Corpse0327
Did you installEventFilter forQDialog
?