QT5中的布局问题
#include "QtGuiApplication11.h"
QtGuiApplication11::QtGuiApplication11(QWidget *parent)
: QWidget(parent)
{
//ui.setupUi(this);
infoLabel = new QLabel(this);
cmdLabel = new QLabel(this);
cmdLine = new QLineEdit(this);
submitButton = new QPushButton(this);
cancelButton = new QPushButton(this);
browserButton = new QPushButton(this);
infoLabel->setText("Please input command in lineedit.");
cmdLabel->setText("open(U):");
cmdLine->clear();
submitButton->setText("submit");
cancelButton->setText("cancel");
browserButton->setText("browser");
QHBoxLayout *cmdLayout = new QHBoxLayout(this);
cmdLayout->addWidget(cmdLabel);
cmdLayout->addWidget(cmdLine);
QHBoxLayout *buttonLayout = new QHBoxLayout(this);
buttonLayout->addWidget(submitButton);
buttonLayout->addWidget(cancelButton);
buttonLayout->addWidget(browserButton);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(infoLabel);
mainLayout->addLayout(cmdLayout);
mainLayout->addLayout(buttonLayout);
this->setLayout(mainLayout);
}
为什么单个布局器可以运行,而这样设置以后,布局器就等同于无效了
下面是头文件(QtGuiApplication11.h)
#pragma once
#include <QtWidgets/QWidget>
#include "ui_QtGuiApplication11.h"
#include "qlabel.h"
#include "qlineedit.h"
#include "qpushbutton.h"
#include "qboxlayout"
class QtGuiApplication11 : public QWidget
{
Q_OBJECT
public:
QtGuiApplication11(QWidget *parent = Q_NULLPTR);
private:
//Ui::QtGuiApplication11Class ui;
QLabel *infoLabel;
QLabel *cmdLabel;
QLineEdit *cmdLine;
QPushButton *submitButton;
QPushButton *cancelButton;
QPushButton *browserButton;
};
下面是主函数文件(main.cpp)
#include "QtGuiApplication11.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication11 w;
w.resize(400, 150);
w.move(300, 200);
w.setWindowTitle("Running...");
w.show();
return a.exec();
}
用的是vs2013+5qt.8