Letholdrus
Letholdrus

Reputation: 1279

Replacing one widget with another during run time and making the new widget show

I create a list of widgets that I store the pointers of these widgets to in a QList. I then have push buttons on the main widget that the user can use to cycle thru the list of widgets.

I use this code to replace the existing widget:

Shape* newShape = shapeList->moveNext();
newShape->draw();
mainLayout->addWidget(newShape, 1, 0);
update();

This code is in the SLOT connected to the push button's clicked signal. This code:

shapeList->moveNext();

Works and an existing already-added-to-list widget is returned. I am just not seeing the the changes on the ui???

Is there any special code needed to make this new widget replace the existing one?

Upvotes: 0

Views: 241

Answers (1)

Amartel
Amartel

Reputation: 4286

I would recommend you using QStackedLayout. All you need to do is - add all your widgets to it and then just change current widget.

Help article.

Upvotes: 3

Related Questions