菜单栏上添加了qt按钮
qt button added on menu bar
我正在尝试将按钮添加到 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));
}
我有两个问题
1.按钮创建在菜单栏的顶部
2.按钮不是一个在另一个下面。
我正在使用 QVBoxLayout。
我认为代码必须更改为:
mRootLayout = new QVBoxLayout(ui->centralWidget);
mRootLayout->addWidget(new QPushButton("Button1", this));
mRootLayout->addWidget(new QPushButton("Button2", this));
没必要setLayout()
。
我正在尝试将按钮添加到 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));
}
我有两个问题 1.按钮创建在菜单栏的顶部 2.按钮不是一个在另一个下面。
我正在使用 QVBoxLayout。
我认为代码必须更改为:
mRootLayout = new QVBoxLayout(ui->centralWidget);
mRootLayout->addWidget(new QPushButton("Button1", this));
mRootLayout->addWidget(new QPushButton("Button2", this));
没必要setLayout()
。