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.
  • ILI Offline
    ILI Offline
    IL
    wrote on 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

    raven-worxR 1 Reply Last reply
    0
    • ILI IL

      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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      • ILI Offline
        ILI Offline
        IL
        wrote on 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
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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

          ILI 1 Reply Last reply
          0
          • raven-worxR raven-worx

            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.

            ILI Offline
            ILI Offline
            IL
            wrote on last edited by
            #5

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

            raven-worxR 1 Reply Last reply
            0
            • ILI IL

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

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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

              • Login

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