Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
a way to reset the layout?
hi folks. I am thinking about how I can reset the layout for my program. The possible solutions are: QStackedWidget/QStackedLayout or delete the layout and re-create new layout.
But my question is: is there any way to just demount all the widgets and sublayouts from the main layout without deleting them? So in this case I do not need to re-initialize all the widgets and sublayouts.
Out of curiosity, why do you need that for ?
@SGaist hi, I'm trying to make a changeable window layout. If the button is pressed the window layout will change from one form to another.
I thought QStackedLayout is not good cause I have to create multiple instances for the windows then stack them together. My priority is the efficiency so this seems not very beneficial for me.
I tried to delete the layout and re-create the layout. It worked, but the program seems so unstable. It will crash with no reason.
alex_malyu last edited by
void QLayout::removeItem(QLayoutItem *item)
void QLayout::removeWidget(QWidget *widget)
or if you only need widgets:
QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively)
Even though I did not see a single case when such approach would provide any advantage it probably may exist.
@alex_malyu hi, thnx for the reply. The thing is every instance has a lots of update functions in it. If I create one more instance and just hide it using QStackedLayout, the update functions will still be called in background and it's not friendly for the RAM.
maybe there's a way to re-write it so the update functions will only be called when the parents Widget is shown.
alex_malyu last edited by alex_malyu
look at QWidget::setUpdatesEnabled(
call it on widget parent of layout you change, make changes, re-enable
@alex_malyu they look very interesting, I'm gonna do some research. Thanks for the help!