Hi,

I have done some searching around on the forums about how to use QButtonGroup and found many of the posts are old, and took a bit to translate in to the latest version. I have things working partially now, but I can't figure out if there is a way to make it assign the ID in a reasonable manner.

Here is my setup. I have 20 buttons in a 4 by 5 grid. This was created using Designer in Qt Creator.

Note: to create the QButtonGroup by right clicking only works when you right click in the Object Inspector, and is not an option if right clicking on the selected buttons themselves. Other forum posts did not say this so it took a while for me to figure that out.

I placed a connect statement in the constructor and was able to get the index output as a qDebug in the destination function. This is where the weirdness starts. I am aware that the auto index uses negative numbers and that is not a problem, but it seems to start from right to left instead of left to right. My index output looks like this. (organised in the arrangement of the buttons)

Qt Code:
  1. -5 -4 -3 -2
  2. -9 -8 -7 -6
  3. -13 -12 -11 -10
  4. -17 -16 -15 -14
  5. -21 -20 -19 -18
To copy to clipboard, switch view to plain text mode 

How can I change this behavior in Designer? The default tab order had the same numbers, but after changing that in Designer it didn't effect the numbering order. I have multiple sets of these button grids so I am trying to avoid having to call setId for each button separately.

I want to trigger a process_buttons(int index) function with the index going left to right, top to bottom. My process_buttons(int) function needs the index in the following mapping. I'm not sure if I need zero indexing, but subtracting a constant isn't a big issue.

Qt Code:
  1. 1 2 3 4
  2. 6 7 8 9
  3. 10 11 12 13
  4. 14 15 16 17
  5. 18 19 20 21
To copy to clipboard, switch view to plain text mode