Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Intercepting Tab key press to manage focus switching manually
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved