Move QtLayout with child widgets
Hello!
Is it possible (easily) to move an layout (QHBoxLayout) with child elements (QButton and QComboBox) from an QGridLayout into another layout (here an QVBoxLayout)?
I tried an grid_layout->removeItem(x) and an vbox_layout->insertItem(1,x), but it does not work.
Any ideas?
Regards
Sven
Re: Move QtLayout with child widgets
Hi, which part does not work? Removing or inserting?
Have you tried calling update() after the operation?
Ginsengelf
Re: Move QtLayout with child widgets
Hello!
The code compiles and there is no error during execution.
Here some code:
Code:
QGridLayout* const glayout
= dynamic_cast<QGridLayout
*>
(form
->layout
());
if (glayout)
{
QLayoutItem* const last_item
= glayout
->itemAtPosition
(glayout
->rowCount
()-1,
0);
if (last_item && dynamic_cast<QHBoxLayout*>(last_item))
{
qDebug() << "Moving...";
glayout->removeItem(last_item);
ui->verticalLayout_frame_edit->insertItem(1, last_item);
}
}
}
Should this be enough to move the layout with all its children or do I have to do something special
to move the children too?
And I tried several "update()" calls...
Regards
Sven
Re: Move QtLayout with child widgets
The widgets that the layout controls the positioning for are children of the widget that layout was applied to, not the layout itself. If the two layouts are not in the same parent widget then you will need to consider this as well.