Unsolved Multiple .ui forms for one class.
-
Hi!
I have an class, that adds new filter to list. I want to transform the window, so it only give to user ability to edit color of filter. I have a form prepared. Is there any option to link two forms to one class, and setup it by ui->setupUI, depending on option triggered by user (Add/Edit)?
-
@sweetMango
Well you can use
http://doc.qt.io/qt-5/quiloader.html
to load an UI file at runtime.You can also use setupUI() but that depends on the ui_widgetname file as its a class with variables in
so not sure what you want to do.You want to replace all widgets in a from with the widgets defines in others forms setup?
You can do
Ui::SomeName * ui2 = new Ui::SomeName;
ui2->setup(this)
To create all widgets defines in SomeName form with other widget as parent. -
Actually I want to change window connected to the class, but keep this class methods and functionality. For eg.
I have this view:
And I want to transform it to this:
Linking new Ui like: Ui::SomeName * ui2 = new Ui::SomeName; says : error: allocation of incomplete type 'Ui::EditColorWindow'
-
@sweetMango Why don't you simply create two different widgets with designer and then put the one you currently need in your dialog? You could even use http://doc.qt.io/qt-5/qstackedwidget.html
-
@jsulm This is what I want to do, but I'm not really sure how to do this. Stacking widgets looks a lil' bit too "overcomplicated".
I thought about something like this:
AddFilter::AddFilter(QWidget* parent, bool flag) : QDialog(parent), ui(new Ui::AddFilter) { if (flag){ ui->setupUi(this); setFixedSize(471, 421); } else{ Ui::EditColorWindow *ui2 = new Ui::EditColorWindow; ui2->setupUi(this); }
but it gives me error mentioned earlier.
-
@sweetMango What you're trying with UI files is overcomplicated.
There is nothing complicated with stacked widgets.
But if you don't want to use them then take a look at http://doc.qt.io/qtcreator/creator-writing-program.html
You simply need to create two widgets, then create and show the one you currently need.
Sounds complicated? Use stacked widgets, should be simpler. -
Append header:
#include "ui_editcolorwindow.h
in .cpp.