【发布时间】:2017-08-04 14:31:39
【问题描述】:
我想在 qt5 中使用布局,但在 Visual Studio 2015 中布局不起作用?
这是我的代码:
layout.h 代码
#ifndef LAYOUT_H
#define LAYOUT_H
#include <QtWidgets/QMainWindow>
#include "ui_layout.h"
class layout : public QMainWindow
{
Q_OBJECT
public:
layout(QWidget *parent = 0);
~layout();
private:
Ui::layoutClass ui;
};
#endif // LAYOUT_H
main.cpp
#include "layout.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
layout w;
QHBoxLayout hb;
QPushButton b("button 0");
QPushButton b1("button 1");
hb.addWidget(&b);
hb.addWidget(&b1);
w.setLayout(&hb);
w.show();
return a.exec();
}
如何解决这个问题?
【问题讨论】:
-
什么是布局?
-
@eyllanesc QHBoxLayout 和 QVBoxLayout
-
QVBoxLayout 和 QHBoxLayout 没有 show 方法。
-
@eyllanesc 我已经添加了头文件。
-
@eyllanesc 我不使用 Qt Designer。
标签: c++ qt visual-c++ qt5