The current approach that I took:
I used a pointer to my current widget (m_pCurrentWdgt
). I were using the widget inside of a simple layout (few elements), hence I could control the position of the widget manually. Otherwise I would use a additional support layout (m_pLayoutWidget
) to place the widget where I want. The replacement worked as follows: When I want to replace the current widget by a new one (pWidget
) I delete the current widget from the support layout and insert the new one in the previous position (e.g. N_WIDGET).
void MyDialog::replaceWidget(QWidget *pWidget) {
this->m_pLayoutWidget->removeWidget(m_pCurrentWidget);
delete m_pCurrentWidget;
m_pCurrentWidget = pWidget;
this->insertWidget(N_WIDGET, m_CurrentWidget);
}
I would like to avoid using Layout here, but at least it worked for me.