How to replace widget without creating object
-
hi ,,,anyone please help me to solve it
To Replace parentwidget i used this codemainpage* mn = new mainpage(ui->widget->parentWidget()); ui->widget->parentWidget()->layout()->replaceWidget(ui->widget,mn->ui->widget); ui->widget=mn->ui->widget; ui->widget= mn;To replace parentwidget many times i created object so issue is 6 times created objects to mainpage class in another classes so when I Integrate BusyCall() API (when i click on Call Tab(call button) ,QMessageBox are showing 6 times),,,on QMessageBox i added one toast message i.e."busy in another call"
-
hi ,,,anyone please help me to solve it
To Replace parentwidget i used this codemainpage* mn = new mainpage(ui->widget->parentWidget()); ui->widget->parentWidget()->layout()->replaceWidget(ui->widget,mn->ui->widget); ui->widget=mn->ui->widget; ui->widget= mn;To replace parentwidget many times i created object so issue is 6 times created objects to mainpage class in another classes so when I Integrate BusyCall() API (when i click on Call Tab(call button) ,QMessageBox are showing 6 times),,,on QMessageBox i added one toast message i.e."busy in another call"
@Dimple Why do you want to replace parent widget? Can you explain better your use case?
And parent widget must be an existing object - how else can it be a parent?
I don't know what your use case is, but what is this new parent widget supposed to be? -
Already mainpage has one widget(parent widget) ,,i want to replace mainpage to show another page(another class widget) i mean child widget ,,,
ex: you are using whatsapp ryt ,,,if you want to make call to ur friend ,you will click on audio button(call button) then u get outgoing page (shows outgoing call page ) so to show outgoing call page(child widget)instead of parent widget page ,, -
Already mainpage has one widget(parent widget) ,,i want to replace mainpage to show another page(another class widget) i mean child widget ,,,
ex: you are using whatsapp ryt ,,,if you want to make call to ur friend ,you will click on audio button(call button) then u get outgoing page (shows outgoing call page ) so to show outgoing call page(child widget)instead of parent widget page ,,@Dimple
Hi
For such design, the StackedWidget is very good
http://doc.qt.io/qt-5/qstackedwidget.html
It allows you to have some pages and flip between them. -
yeah you are ryt but now have to continue this only ,,,my senior gave one solution for this that is ,,

if u knw how to create child widget ? suggest me please
-
@Dimple
That means the layout owns that other widget and im not sure replaceWidget will handle that correctly.
You can use http://doc.qt.io/qt-5/qlayout.html#takeAt
To remove the Other widget from its layout first, then
replaceWidget should work.However, this is a very bad way and will take tons of house keeping if you plan to go back and forth between the pages.
Using StackedWidget would just work and ensure the sub widgets only be created once.