I created QT custom widget MyWidget
with a .ui
file. But when I place QWidget
to MainWindow
in QT designer and promote it to MyWidget
, it just renders an empty widget.
I figured out why it doesn't work. In generated file ui_mainwindow.h
in function setupUi
is code for displaying my widget following:
widget = new MyWidget(centralWidget);
widget->setObjectName(QString::fromUtf8("widget"));
verticalLayout->addWidget(widget);
It works, when I call Ui::MyWidget.setupUi
(replace the code above with following):
widget = new MyWidget(centralWidget);
Ui::MyWidget uiOfWidget;
uiOfWidget.setupUi(widget);
widget->setObjectName(QString::fromUtf8("widget"));
verticalLayout->addWidget(widget);
So my question is, how it's possible to reach one of following:
- Generate code like this automatically when compiling
MainWindow.ui
file - Remove the need for calling
Ui::MyWidget.setupUi
- Or other fix...?
I use QT5. Thank you!