手工布局: Test2_1
添加类为:Qt Class
//myproject.h文件
#pragma once
#include <QWidget>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QPushButton>
class myproject : public QWidget
{
Q_OBJECT
public:
myproject(QWidget *parent);
~myproject();
private:
QLineEdit* m_Line;
QPlainTextEdit* m_Plain;
QPushButton* m_Push;
};
//myproject.cpp文件
#include "myproject.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
myproject::myproject(QWidget *parent)
: QWidget(parent)
{
m_Line = new QLineEdit(this);
m_Plain = new QPlainTextEdit(this);
m_Push = new QPushButton(this);
m_Push->setText("OK");
//layout为一个局部变量(以后不会再使用),而非成员变量(定义在头文件里,以后可能还会被调用)
QHBoxLayout* layout1 = new QHBoxLayout;
layout1->addWidget(m_Line);
layout1->addWidg