View Full Version : How to delete ui member?
codeslicer
25th March 2008, 02:24
So this is the situation: I have created my own custom widget, and it uses 2 separate forms, designed in Designer and defined in the private section of the header file. When I switch between the two forms, I have to delete the objects and layout in the other form, otherwise I get a mess.
I use something like myForm.setupUi() and lster myForm2.setupUi(), but doing that causes problems. So I need to somehow delete the objects created by the setupUi() function. I tried qDeleteAll(children()) but that deleted everything in the widget, not just in the UI part, and I don't want that.
Basically I want to undo the operations of setupUi(). Any ideas? Thanks! :p
yogeshm02
25th March 2008, 06:04
So this is the situation: I have created my own custom widget, and it uses 2 separate forms, designed in Designer and defined in the private section of the header file. When I switch between the two forms, I have to delete the objects and layout in the other form, otherwise I get a mess.
What kind of mess?
jpn
25th March 2008, 13:30
The easiest way will be to use separate widgets instead of "this". Using QStackedWidget is also one option.
codeslicer
25th March 2008, 23:07
Thanks for answering, but I meant something else I guess...
Check post 20 on this thread: http://www.qtcentre.org/forum/f-qt-programming-2/t-still-need-help-best-way-to-have-application-skins-12013.html
You told me I have to delete the old objects on the form, that's what I have to do. However doing qDeleteAll(children()) deletes everything in that class.
Anyways, thanks in advance! ~codeslicer
codeslicer
26th March 2008, 10:59
*BUMP*
jpn if only you could help :p
jpn
26th March 2008, 11:38
However doing qDeleteAll(children()) deletes everything in that class.
This is exactly why I suggested introducing an additional layer. Just allocate a plain wrapper QWidget on which you load the designed form. Then you can simply delete that wrapper widget whenever you want.
codeslicer
1st April 2008, 02:06
Sorry for the late reply...
The problem is that I want to use 2 separate, different forms in the same class.
I can't create a "wrapper" widget, is there any way of excluding some objects from the children() list? If I use qDeleteAll(children()) then I want to prevent some of the objects from getting deleted, how would I do that? Can I treat it as a regular QList and use the negative (-) operator to remove certain objects? How would I do that? Would this work:
QObject myPermanentObject;
QObject myPermanentObject2;
...
QObjectList childrenList = children();
childrenList.removeAt(indexOf(myPermanentObject));
childrenList.removeAt(indexOf(myPermanentObject2)) ;
...
qDeleteAll(childrenList);
Thanks :)
The problem is that I want to use 2 separate, different forms in the same class.
I can't create a "wrapper" widget
Why would that be?
{
// setting up a common layout
layout = new QVBoxLayout(this);
layout->setMargin(0);
// creating common actions (which are not deleted when changing the form)
QAction* action = new QAction(this);
...
}
{
// setting up form A
wrapper = new QWidget(this);
oneUi.setupUi(wrapper);
layout->addWidget(wrapper);
}
{
// setting up form B
wrapper = new QWidget(this);
anotherUi.setupUi(wrapper);
layout->addWidget(wrapper);
}
{
// cleaning up either form
delete wrapper;
}
Or just throw the whole complex idea away and start using QStackedWidget. :p
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.