[SOLVED] Intercepting Tab key press to manage focus switching manually



  • I want to intercept Tab key press in my main window to prevent Qt from switching focus. Here's what I've
    tried so far:
    @bool CMainWindow::event(QEvent * e)
    {
    if (e && e->type() == QEvent::KeyPress)
    {
    QKeyEvent * keyEvent = dynamic_cast<QKeyEvent*>(e);
    if (keyEvent && keyEvent->key() == Qt::Key_Tab)
    return true;
    }
    return QMainWindow::event(e);
    }@

    This doesn't work, event isn't called when I press Tab. neither do keyPressEvent and eventFilter. How to achieve what I want?



  • Found a solution: reimplementing virtual bool QApplication::notify(QObject * receiver, QEvent * e) and pasting the code from my question there works.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.