Boldijar Paul
Boldijar Paul

Reputation: 5495

qt button added on menu bar

I'm trying to add buttons to a vertical layout in QT.

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    mRootLayout = new QVBoxLayout(this);
    setLayout(mRootLayout);

    mRootLayout->addWidget(new QPushButton("Button1", this));
    mRootLayout->addWidget(new QPushButton("Button2", this));

}

I have 2 problems 1. The buttons are created on top of the menu bar 2. The buttons are not one under the other one.

I'm using a QVBoxLayout.

enter image description here

Upvotes: 0

Views: 1948

Answers (1)

Shtol Krakov
Shtol Krakov

Reputation: 1280

I think code must be change to:

mRootLayout = new QVBoxLayout(ui->centralWidget);
mRootLayout->addWidget(new QPushButton("Button1", this));
mRootLayout->addWidget(new QPushButton("Button2", this));

It's not necessary do setLayout().

Upvotes: 1

Related Questions