Hi,
I'm defining a palette through QPushButtons, as shown below:
list_before.png
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:
delete item;
rightbox->insertWidget(index + 1, paletItems[index]);
paletItems.swap(index,index+1);
QLayoutItem *item = rightbox->takeAt(index);
delete item;
rightbox->insertWidget(index + 1, paletItems[index]);
paletItems.swap(index,index+1);
To copy to clipboard, switch view to plain text mode
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.
list_after.png
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?
Bookmarks