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. Application menu with many rows and columns.
Forum Updated to NodeBB v4.3 + New Features

Application menu with many rows and columns.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k 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.
  • P Offline
    P Offline
    poor_robert
    wrote on last edited by
    #1

    Hello,

    I have strange problem. I'm trying to implement menu (of buttons) with 4 rows and 4 columns, which looks basically like this:


    | 1 2 3 4 |

    | 5 6 7 8 |

    | 9 A B C |

    | D E F 0 |


    I leyd (sorry, I forgot past form of lay...) down buttons with QGridLayout, but it doesn't work in desired way. Problem is that, when I have focus on object no. 7 and I press "down" I wold like to jump to row below.

    I know that I can place those buttons in somekind of 2d table and write my own focus-movement logic, but maybe someone knows some other solution.

    greetings!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      AFAIK, a QGridLayout does not implement focus movement using the arrow keys for you, so you'll have to do it yourself. Should not be too difficult, though. You can create your own QGridLayout subclass, do it in the QWidget subclass that uses your grid layout, or use an event filter.

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

        I think I would use this approach:

        Create a QObject-derived class that takes in it's constructor a QGridLayout pointer (and the usual QObject parent pointer). In the constructor:

        • iterate over the layout to get the widgets
        • install an eventfilter on all of these widgets
        • reimplement the eventFilter method, and respond to the events for the arrow keys by shifting focus
        • use QLayout::indexOf(), QGridLayout::getItemPosition and QGridLayout::itemAtPosition to find out
          where the current item is located, and where to move next.

        This way, you can add this functionality to any grid layout by just instantiating an instance of this self-contained class.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          poor_robert
          wrote on last edited by
          #4

          Thanks gentelmen for Your answers. I will use one of your suggestions to solve this problem. I also will try to post some code here, that others won't have to ask again.

          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