简体   繁体   English

在菜单栏上添加了qt按钮

[英]qt button added on menu bar

I'm trying to add buttons to a vertical layout in QT. 我正在尝试将按钮添加到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. 我有2个问题1.在菜单栏的顶部创建了按钮2.按钮不是一个在另一个下面。

I'm using a QVBoxLayout. 我正在使用QVBoxLayout。

在此处输入图片说明

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() . 不必做setLayout()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM