Repainting/Refreshing Layout after one QWidget * has changed
Hi,
I have a layout filled with 2 widgets.
I would like to replace one of the widgets of the layout using a signal/slot mechanism.
What do I need to do so that the layout is repainted/refreshed using the new widget after the widget has been changed ?
Code:
DriverView
::DriverView( QWidget* parent
) :{
// Title
title = new TitleFrame(this,"Actual Driver");
// Body
body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
// Layout
mainLayout->addWidget(title);
mainLayout->addWidget(body);
mainLayout->setContentsMargins (0, 0, 0, 0);
setLayout(mainLayout);
connect(driverFactory(),SIGNAL(driverHasChanged()), this, SLOT(refreshDriverView()));
}
Code:
void
DriverView::refreshDriverView() {
body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
// repaint(); doesn't work
// update(); doesn't work
}
Re: Repainting/Refreshing Layout after one QWidget * has changed
You only change the body variable. Qt still has a pointer to the old widget. See QStackedWidget and QStackedLayout. Also don't forget to show the new widget.
Re: Repainting/Refreshing Layout after one QWidget * has changed
Is there a way to tell QT to use the pointer on the new widget instead of the pointer of the old one ?
Alternatively is it possible to delete the entire layout and create a new one ?
Re: Repainting/Refreshing Layout after one QWidget * has changed
This seems to work:
Code:
void
DriverView::refreshDriverView() {
body->hide();
mainLayout->removeWidget(body);
body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
mainLayout->addWidget(body);
body->show();
}
Is there anything that speeks against this ?
Re: Repainting/Refreshing Layout after one QWidget * has changed
Quote:
Originally Posted by
schall_l
Is there anything that speeks against this ?
Where do you get rid of unused widgets?