QT笔记-布局

1 QT中使用布局器QLayout布局

2自动计算各个空间的大小和位置 采用的既定policy策略来调整子窗口的大小和位置

3QHBoxLayout横向布局  QVBoxLayout纵向布局

  • QHBoxLayout ( QWidget * parent, int margin = 0, int spacing = -1, const char * name = 0 )
  • QHBoxLayout ( QLayout * parentLayout, int spacing = -1, const char * name = 0 )
  • QHBoxLayout ( int spacing = -1, const char * name = 0 )

  使用三部曲:(1)创建控件对象(2)创建布局器(3)使用布局器

Mywin.h

 1 #ifndef MYWIN_H
 2 #define MYWIN_H
 3 
 4 #include <QWidget>
 5 
 6 // 添加头文件
 7 #include <QVBoxLayout>
 8 #include <QLineEdit>
 9 #include <QPlainTextEdit>
10 
11 class MyWin : public QWidget
12 {
13     Q_OBJECT
14 
15 public:
16     MyWin(QWidget *parent);
17     ~MyWin();
18 
19 private:
20     QLineEdit* m_lineEdit;
21     QPlainTextEdit* m_textEdit;
22 
23 };
24 
25 #endif // MYWIN_H

Mywin.cpp

#include "MyWin.h"

MyWin::MyWin(QWidget *parent)
    : QWidget(parent)
{
    // 创建控件对象
    m_lineEdit = new QLineEdit(this);
    m_textEdit = new QPlainTextEdit(this);

    // 创建布局器
    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->addWidget(m_lineEdit); // 将第一个box添加到布局器
    layout->addWidget(m_textEdit); // 将第二个box添加到布局器

    // 使用布局器
    this->setLayout(layout);
}

MyWin::~MyWin()
{

}

 

转载于:https://www.cnblogs.com/lanjianhappy/p/6339825.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值