Can't add widget created by Designer
-
f->show(); shows my widget as different window.
and does only if I didn't added my widget to any of layouts. -
You should read the handbook carefully. Usually we can create a class which derived from QWidget or QMainWindow,or something. And define a private member variable Ui::Fuel_Widget *ui. Then use it.
Fortunately, the Qt Creator will help you make all things to be done.Or you can try UiLoader to use a single UI file.
-
Run Qt Creator, Use menu "New file or Projects"
A dialog will show out( choose a template)
Choose "Qt" under "Files and Classes" at left
Choose "Qt Designer Form Class" .... -
bq. Run Qt Creator, Use menu “New file or Projects”
A dialog will show out( choose a template)
Choose “Qt” under “Files and Classes” at left
Choose “Qt Designer Form Class” ….I've made that.
Now trying to use created class with
@
Fuel_widget *f = new Fuel_widget;
ui->verticalLayout->addWidget(f);
@but nothing happens again :(
-
bq. You should read the handbook carefully. Usually we can create a class which derived from QWidget or QMainWindow,or something. And define a private member variable Ui::Fuel_Widget *ui. Then use it.
Fortunately, the Qt Creator will help you make all things to be done.I've tried that but this doesn't work just like previous variant :(
-
Are you trying to create a multi or single document interface? What I'm asking is do you want your widget to be created in a new window within your mainwindow? If yes, then you need to use an MDI.
@
QMdiArea *myArea = new QMdiArea;
Fuel_widget *f = new Fuel_widget;
QMdiSubWindow *myWidgetSubWindow = myArea->addSubWindow(f);
@ -
bq. Are you trying to create a multi or single document interface?
no, I'm just trying to draw something I created with QT Designer within my main window couple times. That is why I made widget and trying to add it to main window.
Am I doing it wrong? -
Did you set the widget as the main windows central widget using QMainWindow::setCentralWidget()?
-
yes, there is such code in 'ui_mainwindow.h' (which is generated by Designer) and it is run when I make mainwindow object (in constructor ui->setupUi(this))
why does it matter?
-
I would recommend reading the "mainwindow documention":http://developer.qt.nokia.com/doc/qt-4.8/QMainWindow.html, and some beginner Qt material - there is a ton available online.
This "thread":http://developer.qt.nokia.com/forums/viewthread/8779 might prove useful as well.