It needs few corrections:
if (object
== condition_text_edit
&& event
->type
() == QEvent::KeyPress) { QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
// key() returns the code of the key that was pressed, so you need to compare it with the keys you want to filter out, for example 'A' character
// see the QKeyEvent::key docs for complete list of key codes
if (keyEvent->key() == Qt::Key_A)
{
qDebug("Enter Key Pressed...");
qDebug()<<keyEvent->key();
// now it will be impossible to type the 'A' char into text edit
return true;
}
}
return QWidget::eventFilter(object,event
);
// you need to call base class implementation to save "normal" behavior }
bool HomeWindow::eventFilter(QObject *object, QEvent *event) {
if (object == condition_text_edit && event->type() == QEvent::KeyPress)
{ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
// key() returns the code of the key that was pressed, so you need to compare it with the keys you want to filter out, for example 'A' character
// see the QKeyEvent::key docs for complete list of key codes
if (keyEvent->key() == Qt::Key_A)
{
qDebug("Enter Key Pressed...");
qDebug()<<keyEvent->key();
// now it will be impossible to type the 'A' char into text edit
return true;
}
}
return QWidget::eventFilter(object,event); // you need to call base class implementation to save "normal" behavior
}
To copy to clipboard, switch view to plain text mode
Bookmarks