码迷,mamicode.com
首页 > 其他好文 > 详细

QT笔记-布局

时间:2017-01-22 12:21:05      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:调整   add   第一个   har   bsp   object   ons   etl   位置   

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()
{

}

 

QT笔记-布局

标签:调整   add   第一个   har   bsp   object   ons   etl   位置   

原文地址:http://www.cnblogs.com/lanjianhappy/p/6339825.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!