PDA

View Full Version : Repainting/Refreshing Layout after one QWidget * has changed



schall_l
7th August 2008, 15:06
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 ?


DriverView::DriverView( QWidget* parent ) :
QWidget( parent )
{
// Title
title = new TitleFrame(this,"Actual Driver");
// Body
body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());

// Layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(title);
mainLayout->addWidget(body);
mainLayout->setContentsMargins (0, 0, 0, 0);
setLayout(mainLayout);

connect(driverFactory(),SIGNAL(driverHasChanged()) , this, SLOT(refreshDriverView()));
}



void
DriverView::refreshDriverView() {
body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
// repaint(); doesn't work
// update(); doesn't work
}

jacek
7th August 2008, 20:50
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.

schall_l
7th August 2008, 23:37
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 ?

schall_l
7th August 2008, 23:42
This seems to work:


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 ?

jacek
8th August 2008, 17:28
Is there anything that speeks against this ?
Where do you get rid of unused widgets?