Qt学习——布局管理器QLayout类
来源:互联网 发布:弱视网络训练 编辑:程序博客网 时间:2024/04/28 14:04
最近感觉没有那么多时间在网上写学习笔记了。还是自己在本子上手写吧。这里只贴上代码和截图记录自己的学习历程。
常用的布局管理有QVBoxLayout,QHBoxLayout,QGridLayout。
下面是综合应用:
新建Qt Gui程序,基类为Dialog
头文件:
#ifndef DIALOG_H#define DIALOG_H#include <QtGui/QDialog>#include <QLabel>#include <QLineEdit>#include <QTextEdit>#include <QComboBox>#include <QGridLayout>#include <QPushButton>#include <QHBoxLayout>#include <QVBoxLayout>class Dialog : public QDialog{ Q_OBJECTpublic: Dialog(QWidget *parent = 0); ~Dialog();private: //左侧的控件 QLabel *UserLabel; QLabel *NameLabel; QLabel *SexLabel; QLabel *DepartLabel; QLabel *AgeLabel; QLabel *OtherLabel; QLineEdit *UserLineEdit; QLineEdit *NameLineEdit; QComboBox *SexComboBox; QTextEdit *DepartTextEdit; QLineEdit *AgeLineEdit; QGridLayout *LeftGridLayout; //右上角 QLabel *HeadLabel; QLabel *HeadIconLabel; QPushButton *UpdateHeadBtn; QHBoxLayout *RightTopHBLayout; //右下角 QLabel *IntroLabel; QTextEdit *IntroTextEdit; QVBoxLayout *RightVBLayout; //底部 QPushButton *OkBtn; QPushButton *CancelBtn; QHBoxLayout *ButtomHBLayout;};#endif // DIALOG_H
源文件:
#include "dialog.h"Dialog::Dialog(QWidget *parent) : QDialog(parent){ //××××××××××××初始化××××××××××××××× setWindowTitle(tr("UserInfo")); UserLabel=new QLabel(tr("用户名:")); UserLineEdit=new QLineEdit; NameLabel=new QLabel(tr("姓名:")); NameLineEdit=new QLineEdit; SexLabel=new QLabel(tr("性别:")); SexComboBox=new QComboBox; SexComboBox->addItem(tr("男")); SexComboBox->addItem(tr("女")); DepartLabel=new QLabel(tr("部门")); DepartTextEdit=new QTextEdit; AgeLabel=new QLabel(tr("年龄")); AgeLineEdit=new QLineEdit; OtherLabel=new QLabel(tr("备注")); OtherLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); //××××××××××××添加左侧×××××××××××××× LeftGridLayout=new QGridLayout(); LeftGridLayout->addWidget(UserLabel,0,0); LeftGridLayout->addWidget(UserLineEdit,0,1); LeftGridLayout->addWidget(NameLabel,1,0); LeftGridLayout->addWidget(NameLineEdit,1,1); LeftGridLayout->addWidget(SexLabel,2,0); LeftGridLayout->addWidget(SexComboBox,2,1); LeftGridLayout->addWidget(DepartLabel,3,0); LeftGridLayout->addWidget(DepartTextEdit,3,1); LeftGridLayout->addWidget(AgeLabel,4,0); LeftGridLayout->addWidget(AgeLineEdit,4,1); LeftGridLayout->addWidget(OtherLabel,5,0,1,2); LeftGridLayout->setColumnStretch(0,1); LeftGridLayout->setColumnStretch(1,3); //×××××××××××××添加右上角××××××××××××××× HeadLabel=new QLabel(tr("头像:")); HeadIconLabel=new QLabel; QPixmap icon("1.bmp"); HeadIconLabel->setPixmap(icon); HeadIconLabel->resize(icon.width(),icon.height()); UpdateHeadBtn=new QPushButton(tr("更新")); RightTopHBLayout=new QHBoxLayout; RightTopHBLayout->setSpacing(20); RightTopHBLayout->addWidget(HeadLabel); RightTopHBLayout->addWidget(HeadIconLabel); RightTopHBLayout->addWidget(UpdateHeadBtn); //×××××××××××××添加右下角××××××××××××××× IntroLabel=new QLabel(tr("个人说明:")); IntroTextEdit=new QTextEdit; RightVBLayout=new QVBoxLayout(); RightVBLayout->setMargin(10); RightVBLayout->addLayout(RightTopHBLayout); RightVBLayout->addWidget(IntroLabel); RightVBLayout->addWidget(IntroTextEdit); //×××××××××××××添加底部××××××××××××××× OkBtn=new QPushButton(tr("确定")); CancelBtn=new QPushButton(tr("取消")); ButtomHBLayout=new QHBoxLayout(); ButtomHBLayout->addStretch(); ButtomHBLayout->addWidget(OkBtn); ButtomHBLayout->addWidget(CancelBtn); //×××××××××××××设置主窗体××××××××××××××× QGridLayout *mainLayout=new QGridLayout(this); mainLayout->setMargin(15); mainLayout->setSpacing(10); mainLayout->addLayout(LeftGridLayout,0,0); mainLayout->addLayout(RightVBLayout,0,1); mainLayout->addLayout(ButtomHBLayout,1,0,1,2); mainLayout->setSizeConstraint(QLayout::SetFixedSize); connect(OkBtn,SIGNAL(clicked()),this,SLOT(accept())); connect(CancelBtn,SIGNAL(clicked()),this,SLOT(reject()));}Dialog::~Dialog(){}
- Qt学习——布局管理器QLayout类
- Qt学习——布局管理器QLayout类 .
- Qt学习——布局管理器QLayout类
- QT开发(二十一)——QT布局管理器
- QT实现竖直方向的窗口布局(使用QLayout类)
- QT学习笔记1---布局管理器
- QT学习笔记----布局管理器的使用
- QT学习笔记----布局管理器的使用
- QT学习笔记----布局管理器的使用
- Qt学习之七:布局管理器
- QT学习笔记----布局管理器的使用
- QT学习笔记12布局管理器
- Qt学习笔记(一)布局管理器
- QT学习笔记(3)布局管理器
- 《学习Qt之路2》笔记:QT布局管理器
- Qt布局管理器入门
- 使用QT布局管理器
- Qt 布局管理器
- Java中引用类型和原始类型的区分
- POJ1256 Anagram STL中的next_permutation()
- Q_CHECK_PTR and “fscanf float or double”
- 字符串中的||去掉
- nmon 的使用
- Qt学习——布局管理器QLayout类
- GetPixel SetPixel bitbil
- Makefile 入门
- 谈谈关于程序员或者IT人员的健康问题,因为自己出现了
- 开启第一步
- 浮点数累加的方法
- yaffs2源代码分析(一)
- Qt学习——基本对话框Q*Dialog类
- 《STL源码剖析》-- stl_slist.h