You can have 'this->setCentralWidget(w);' OR 'ui->setupUi(this);', not both.
To stick new widget inside the 'ui' you could do something like this:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->centralWidget->setLayout(l);
l->addWidget(w);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QVBoxLayout* l = new QVBoxLayout();
ui->centralWidget->setLayout(l);
QWidget* w = new QWidget();
l->addWidget(w);
}
To copy to clipboard, switch view to plain text mode
That will insert new widget inside the ui created in the designer.
That's assuming this ui is empty, if you've something inside already, just add new widget to existing layout or parent it to existing widget, ie:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QWidget* w = new QWidget(ui->someExistingWidget);
}
To copy to clipboard, switch view to plain text mode
Bookmarks