View Full Version : Change QVBoxLayout index?

26th April 2012, 21:42
I'm defining a palette through QPushButtons, as shown below:
If you press one of the buttons, and use arrowUp and arrowDown keys, you can traverse the list.

If you for some reason want to rearrange the list you can do so by:
1. Click one of the buttons
2. Press 'A' if you want the button upwards, or 'Z' if you want it downwards

This is the code:

QLayoutItem *item = rightbox->takeAt(index);
delete item;
rightbox->insertWidget(index + 1, paletItems[index]);

rightbox is a QVBoxLayout, and paletitems is a QList containing the buttons.

Here I have clicked the 'color 4' button, and moved it two places down.
It works fine except one thing:
When you traverse the palette with the arrow-keys, it is af if the buttons has kept the original index in the layout?
It jumps from 'color 3' to 'color 4', skipping the two colors in between. Very annoying.

Why is this, and can I avoid it?
Can I vhange the index of the layout-items?

27th April 2012, 01:02
I assume you are relying on the normal focus navigation for "traverse the list". You have rearranged the widgets on screen but they still carry their original tab order information.

27th April 2012, 01:51
Thank you! Works like a charm...