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. QMenu TAB access through keyboard
Forum Updated to NodeBB v4.3 + New Features

QMenu TAB access through keyboard

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 465 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.
  • A Offline
    A Offline
    anshah
    wrote on last edited by anshah
    #1

    I have a QMenu inside a QMenuBar as one of the components inside a QMainWindow.

    I want to access the QMenu through keyboard TAB access but the TAB cycles through all the components in the QMainWIndow and skips the QMenu. I tried to set the TAB order in QMainWIndow by calling "setTabOrder" but that didn't work at all.

    Here's my QMenu setup inside the QMainWindow:

    QHBoxLayout *m_pMenuLayout;
    QMenuBar    *m_pMenuBar;
    QMenu       *m_pMenu;
    
    m_pMenuLayout->addWidget(m_pMenuBar);
    m_pMenuLayout->setAlignment(m_pMenuBar, Qt::AlignRight);
    
    m_pMainLayout->addLayout(m_pMenuLayout);
    m_pMainLayout->setAlignment(m_pMenuLayout, Qt::AlignTop);
    

    I tried the following in my QMainWindow class:

    setFocusProxy(m_pMenu);
    setFocusPolicy(Qt::StrongFocus);
    
    setTabOrder(m_pMenu,     m_pButton);
    setTabOrder(m_pButton,   m_pComboBox);
    setTabOrder(m_pComboBox, m_pMenu);
    

    When I do this and press TAB, the focus just cycles back and forth from the QButton to the QComboBox without giving focus to QMenu.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Likely because it's not how menu are usually accessed by keyboards.

      It is usually through accelerators (using the & char) and the alt key.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anshah
        wrote on last edited by
        #3

        Is there an example of keyboard accelerators you can point me to?

        Is there anyway to override a function to add in TAB into the rotation?

        In my case, the QMenu is just an icon in the top right of my main window. What I want to do is have the QMenu come into focus the first time I press TAB and then cycle through all the components on the screen every subsequent TAB press event...eventually cycling back to the QMenu.

        Is there a possible way to do that?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          See the QAction class details.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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