Solved how to attach class to qt project without ui file?
-
@mpergand said in how to attach class to qt project without ui file?:
turquoise widget
OknoWibora::OknoWibora(QWidget *parent)
: QMainWindow(parent)
{
display = new QLineEdit();QGridLayout *mainLayout = new QGridLayout; oknonastr = new Widgets::OknoNastroek(this); mainLayout->addWidget(oknonastr); mainLayout->addWidget(display);
}
-
@timob256 said in how to attach class to qt project without ui file?:
windowspar (QWidget * parent = 0);
~ windowspawn ();Typo or does your class c'tor have a different name than your d'tor?
-
@Pl45m4 ????? I don't have such variables c'tor and d'tor
-
@timob256 c'tor - constructor, d'tor - destructor.
Not vars but methods and yes, you have them. -
@timob256 said in how to attach class to qt project without ui file?:
QGridLayout *mainLayout = new QGridLayout;
oknonastr = new Widgets::OknoNastroek(this);
mainLayout->addWidget(oknonastr);
mainLayout->addWidget(display);You're missing something ;)
Find a perfect example for you:
https://github.com/HBPVIS/Servus/blob/master/apps/servusBrowser.cpp -
OknoWibora::OknoWibora(QWidget *parent)
: QMainWindow(parent)
{
// QGridLayout *mainLayout = new QGridLayout;
// oknonastr = new Widgets::OknoNastroek(this);
// mainLayout->addWidget(oknonastr);
// mainLayout->addWidget(display);QGridLayout *mainLayout = new QGridLayout; oknonastr = new Widgets::OknoNastroek(this); mainLayout->addWidget(oknonastr);
}
the code works but not as I need it, the turquoise square does not stretch, in a separate project it is perfectly stretched to the specified values :(
-
OK, I explain in details:
When you don't use an UI from the Designer, you need to:
- set the central widget
- add a layout to the central widget
- add others widgets to the layout
QWidget* centralWidget= new QWidget; setCentralWidget(centralWidget); QBoxLayout* layout= new QVBoxLayout; centralWidget->setLayout(layout); layout->addWidget( *yourTurquoiseWidget*);
-
-
@timob256 said in how to attach class to qt project without ui file?:
OknoWibora::OknoWibora(QWidget *parent)
: QMainWindow(parent)
{
// QGridLayout *mainLayout = new QGridLayout;
// oknonastr = new Widgets::OknoNastroek(this);
// mainLayout->addWidget(oknonastr);
// mainLayout->addWidget(display);QGridLayout *mainLayout = new QGridLayout; oknonastr = new Widgets::OknoNastroek(this); mainLayout->addWidget(oknonastr);
}
the code works but not as I need it, the turquoise square does not stretch, in a separate project it is perfectly stretched to the specified values :(
this work
thsanks mpergand -
@timob256 said in how to attach class to qt project without ui file?:
mainLayout
You did not add this layout to any widget or other layout. Don't know how this can work...