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. Arrows Key order in grid layout
QtWS25 Last Chance

Arrows Key order in grid layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
keysgridlayoutfocus issue
6 Posts 2 Posters 5.9k 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.
  • I Offline
    I Offline
    IL
    wrote on 14 Jan 2016, 07:05 last edited by
    #1

    I have created 10 push buttons on my application and set them as grid layout, 5 rows and 2 columns.
    When I run my application and using the arrows for navigation between the buttons, I get unclear focus movment.
    My expectation is to:

    • Get the upper button when I go up.
    • Get the left button when I go left.
      etc...

    But instead the focus move not alwayes to the directation that I want it to go.
    What am I missing?

    Best regards,
    IL

    R 1 Reply Last reply 14 Jan 2016, 07:23
    0
    • I IL
      14 Jan 2016, 07:05

      I have created 10 push buttons on my application and set them as grid layout, 5 rows and 2 columns.
      When I run my application and using the arrows for navigation between the buttons, I get unclear focus movment.
      My expectation is to:

      • Get the upper button when I go up.
      • Get the left button when I go left.
        etc...

      But instead the focus move not alwayes to the directation that I want it to go.
      What am I missing?

      Best regards,
      IL

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 14 Jan 2016, 07:23 last edited by
      #2

      @IL said:

      What am I missing?

      sorry, but who should be able to answer this question when you don't post a single line of code?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • I Offline
        I Offline
        IL
        wrote on 14 Jan 2016, 07:37 last edited by
        #3

        Hi,
        The question is theory and very simple.
        What is the focus or navigation policy when using grid layout?
        Is there vertical movement or horizontal movement in grid layout.
        because I get something between.

        Thanks,

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 14 Jan 2016, 08:08 last edited by
          #4

          ok now i got you.
          This is what happens:

          1. keyPressEvent() handler of the button (QAbstractButton) catches the up/left and down/right keys
          2. then it calls focusNextPrevChild() on it's parent widget
          3. the default implementation takes the current focus widget and focuses the next widget in the child list

          So the order is given by the order you added the child widget (buttons) to the parent widget.

          So to achieve what you want you would either need subclass your buttons (or install an eventfilter on them) and catch the up/down/right/left keys and focus the next button by yourself.

          Call QLayout::indexOf() and use QGridLayout::getItemPosition() to get the row and column of the current focused widget and determine which item to focus next.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          I 1 Reply Last reply 14 Jan 2016, 11:10
          0
          • R raven-worx
            14 Jan 2016, 08:08

            ok now i got you.
            This is what happens:

            1. keyPressEvent() handler of the button (QAbstractButton) catches the up/left and down/right keys
            2. then it calls focusNextPrevChild() on it's parent widget
            3. the default implementation takes the current focus widget and focuses the next widget in the child list

            So the order is given by the order you added the child widget (buttons) to the parent widget.

            So to achieve what you want you would either need subclass your buttons (or install an eventfilter on them) and catch the up/down/right/left keys and focus the next button by yourself.

            Call QLayout::indexOf() and use QGridLayout::getItemPosition() to get the row and column of the current focused widget and determine which item to focus next.

            I Offline
            I Offline
            IL
            wrote on 14 Jan 2016, 11:10 last edited by
            #5

            @raven-worx
            Thanks for the clarification,
            Can you give more details about what is event filter installation?

            R 1 Reply Last reply 14 Jan 2016, 11:56
            0
            • I IL
              14 Jan 2016, 11:10

              @raven-worx
              Thanks for the clarification,
              Can you give more details about what is event filter installation?

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 14 Jan 2016, 11:56 last edited by
              #6

              @IL
              here ya go

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0

              1/6

              14 Jan 2016, 07:05

              • Login

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