zoukankan      html  css  js  c++  java
  • 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()
    {
    
    }
  • 相关阅读:
    让你平步青云的10个谈话技巧
    瑞士心理学家和精神分析医师――荣格
    市场倍增理论
    淘宝网格,淘宝富人群
    波波的个人简历
    磁盘修复工具
    9种没结果的爱(未婚者必读)!!!
    网络投机市场
    网页数据抽取的方法介绍
    C#扩展方法试用
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/6339825.html
Copyright © 2011-2022 走看看