anda_skoa you mean something like that:
main.cpp
int main(int argc, char *argv[])
{
MyWidget w;
app.installEventFilter(&w);
w.show();
return app.exec();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget w;
app.installEventFilter(&w);
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
event filter in MyWidget
{
if ( event
->type
() == QEvent::KeyPress) { QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
if( keyEvent->modifiers() == Qt::ControlModifier ) {
switch (keyEvent->key()) {
case Qt::Key_M:
ui->actionShow_menu->setChecked(!ui->actionShow_menu->isChecked());
return true;
case Qt::Key_Left:
prevPage();
return true;
case Qt::Key_Right:
nextPage();
return true;
}
return false;
}
}
return QObject::eventFilter(object, event
);
}
bool MyWidget::eventFilter(QObject *object, QEvent *event)
{
if ( event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if( keyEvent->modifiers() == Qt::ControlModifier ) {
switch (keyEvent->key()) {
case Qt::Key_M:
ui->actionShow_menu->setChecked(!ui->actionShow_menu->isChecked());
return true;
case Qt::Key_Left:
prevPage();
return true;
case Qt::Key_Right:
nextPage();
return true;
}
return false;
}
}
return QObject::eventFilter(object, event);
}
To copy to clipboard, switch view to plain text mode
This way is correctly?
Next question, in eventFilter If I want to have "global event handler" I do not need check which object send current event, I am right? So I do not need line:
if( object == someWidget ) {
// task
}
if( object == someWidget ) {
// task
}
To copy to clipboard, switch view to plain text mode
Thanks,
Bookmarks