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. Handling TAB-presses exclusively
Forum Updated to NodeBB v4.3 + New Features

Handling TAB-presses exclusively

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 340 Views
  • 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by qwasder85
    #1

    Following situation:

    My UI has top-level tabs that can contain multiple child widgets several levels deep. I want to use (CTRL-)TAB to navigate between those top-level tabs, and only for that.

    I've overwritten the keyPressEvent(QKeyEvent)*-function for that purpose. This catches every keypress correctly EXCEPT for TAB. I assume this is because TAB is, by default, used to switch focus between all widgets on the screen (which I can observe). Apparently this also happens before my function can catch the TAB press, so it never receives it.

    How can I correct this behavior? My first idea was to loop through all of the widgets and set their FocusPolicy to NoFocus, but that seems too hacky and I'm not even sure whether it would work.

    The second idea was to make sure that the QTabWidget containing the top-level tabs never loses its focus, so I can just utilize its built-in TAB-navigation. But there seems to be no way to force the focus on a single widget without wild hacks (like listening for the focusChangedEvent and then manually returning the focus to the QTabWidget...).

    It feels like I'm going all wrong about this, can anyone help me out here?

    There's gotta be a better way!

    JonBJ 1 Reply Last reply
    0
    • qwasder85Q qwasder85

      Following situation:

      My UI has top-level tabs that can contain multiple child widgets several levels deep. I want to use (CTRL-)TAB to navigate between those top-level tabs, and only for that.

      I've overwritten the keyPressEvent(QKeyEvent)*-function for that purpose. This catches every keypress correctly EXCEPT for TAB. I assume this is because TAB is, by default, used to switch focus between all widgets on the screen (which I can observe). Apparently this also happens before my function can catch the TAB press, so it never receives it.

      How can I correct this behavior? My first idea was to loop through all of the widgets and set their FocusPolicy to NoFocus, but that seems too hacky and I'm not even sure whether it would work.

      The second idea was to make sure that the QTabWidget containing the top-level tabs never loses its focus, so I can just utilize its built-in TAB-navigation. But there seems to be no way to force the focus on a single widget without wild hacks (like listening for the focusChangedEvent and then manually returning the focus to the QTabWidget...).

      It feels like I'm going all wrong about this, can anyone help me out here?

      There's gotta be a better way!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @qwasder85 said in Handling TAB-presses exclusively:
      I cannot comment on whether your approach is best or not. But for dealing with Tab correctly, have you read through https://stackoverflow.com/questions/18160051/intercepting-tab-key-press-to-manage-focus-switching-manually (or the thread https://forum.qt.io/topic/30547/solved-intercepting-tab-key-press-to-manage-focus-switching-manually in this forum) ? Both the answers there, https://stackoverflow.com/a/18161997/489865 and https://stackoverflow.com/a/21351638/489865, look like possible solutions?

      qwasder85Q 1 Reply Last reply
      1
      • JonBJ JonB

        @qwasder85 said in Handling TAB-presses exclusively:
        I cannot comment on whether your approach is best or not. But for dealing with Tab correctly, have you read through https://stackoverflow.com/questions/18160051/intercepting-tab-key-press-to-manage-focus-switching-manually (or the thread https://forum.qt.io/topic/30547/solved-intercepting-tab-key-press-to-manage-focus-switching-manually in this forum) ? Both the answers there, https://stackoverflow.com/a/18161997/489865 and https://stackoverflow.com/a/21351638/489865, look like possible solutions?

        qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by
        #3

        @JonB Thanks, I'll do that.

        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