Moving widgets within a layout.
I am using QVBoxLayout to have a vertical list of custom composite widgets which contain an up and down button, so to move that widget up and down within the list.
It doesn't work.
Do I have to delete and then recreate the widget in order to move it ?
I have tried using layout->remove() and layout->insert() but it doesn't appear to be working.
Re: Moving widgets within a layout.
Re: Moving widgets within a layout.
Wow ! Fast reply !
IIRC takeAt() is only in qt4, and so far I'm using qt3.
Re: Moving widgets within a layout.
Oh, sorry for that. In your case use QBoxLayout::insertWidget() and QLayout::remove().
2 Attachment(s)
Re: Moving widgets within a layout.
Just did that, and I am using ::findWidget(*QWidget) to get the widget index number, and it works at first, then it goes haywire.
I have 3 sample widgets included, like this:
Attachment 1224
and I can move number 2 up to the top by pushing the up button, like this:
Attachment 1223
but if I try to move number 1 back to the top, I get no response. If I push the up button a second time, it doesn't move. In fact, if a push the up buttons a few times, none of them respond.
I have not implemented the other buttons yet.
Here is the relevant code (it is declared as a slot in the header). PositionElementLine inherits QWidget.
Code:
void PositionElementBox::up(PositionElementLine *line)
{
int index = boxLayout->findWidget( line );
if(index > 0 ) //an index of 0 means the widget is at the top !!
{
boxLayout->remove(lineList.at(index));
boxLayout->insertWidget( ( index - 1 ), line );
}
}
Re: Moving widgets within a layout.
oops! The error is in line 7. the lineList is copied from old code. should be
->remove(line);
Re: Moving widgets within a layout.
Why not implement it as QTable and QTableItems and simply forget about the problem? :)