I do have a QVBoxLayout
that contains some custom widgets, which themselves mainly consist of a label and two buttons. You can almost speak of some kind of selfmade table in a way. I know that there are ready-made table widgets available, but I'd like to use my own.
What I want to achieve is this: when I click the "up" button in one of the widgets, it should move up, or to put it differently: it should change its current position/index within the parent QVBoxLayout
in a way that it moves one step up (or down accordingly) with every click. Is that possible? How can I achieve that? I need that as a user-friendly way to set the order of items within that layout.
I began with trying to get the parent layout from within my widget:
QVBoxLayout* myLayout = qobject_cast<QVBoxLayout*>(this->parentWidget());
That seems to work, but how to go on from here? Thanks for your help!
You can try something like this:
Agree with C.E. Gesser, there's no interface like "setIndex" for layoutitems within layout.
If you are implementing some application like a chess on chessboard, where moving widget operates frequently, QGraphicsView + QGraphicsItem (sa QWidgetItem) might be helpful.