Qt综合使用布局管理器(QVBoxLayout,QHBoxLayout,QGridLayout)
2017-12-23 18:13
519 查看
一般界面设计都会有主布局,主布局一般都采用垂直布局(QVBoxLayout),因为界面大都自上而下浏览观看,才符合人类习惯,
布局和布局之间我们都可以通过addSpacing(int)去调整,布局内容可通过setContentsMargins(int left,int top,int right,int bottom)调整
Example:
Run:
布局和布局之间我们都可以通过addSpacing(int)去调整,布局内容可通过setContentsMargins(int left,int top,int right,int bottom)调整
Example:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { QVBoxLayout* mainlayout = new QVBoxLayout(); QGridLayout* layout = new QGridLayout(); QLabel* l1 = new QLabel("Name(N)"); QLineEdit* name = new QLineEdit(); QLabel* l2 = new QLabel("Sex(S)"); QComboBox* sex = new QComboBox(); sex->addItem("Man"); sex->addItem("Woman"); sex->setCurrentIndex(0); QLabel* l3 = new QLabel("Age(A)"); QSpinBox* age = new QSpinBox(); age->setMinimum(0); age->setMaximum(10); QLabel* l4 = new QLabel("Email(E)"); QLineEdit* email = new QLineEdit(); layout->addWidget(l1,0,0,1,1); layout->addWidget(name,0,2,1,5); layout->addWidget(l2,1,0,1,1); layout->addWidget(sex,1,2,1,5); layout->addWidget(l3,2,0,1,1); layout->addWidget(age,2,2,1,5); layout->addWidget(l4,3,0,1,1); layout->addWidget(email,3,2,1,5); mainlayout->addLayout(layout); mainlayout->addSpacing(50); QHBoxLayout* hlayout = new QHBoxLayout(); QFontComboBox* font = new QFontComboBox(); QPushButton* submit = new QPushButton("Sumbit"); hlayout->addWidget(font); hlayout->addWidget(submit); QVBoxLayout* vlayout = new QVBoxLayout(); QLineEdit* le = new QLineEdit(); vlayout->addLayout(hlayout); vlayout->addWidget(le); vlayout->addSpacing(10); vlayout->setContentsMargins(10,10,10,10); layout->setContentsMargins(10,10,10,10); mainlayout->addLayout(layout); mainlayout->addLayout(vlayout); setLayout(mainlayout); ui->setupUi(this); }
Run:
相关文章推荐
- Qt下布局器的使用(QHBoxLayout 、 QVBoxLayout、 QGridLayout)
- Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
- 1QPushButton的使用,QLineEdit的使用,设置组件位置,布局(QHBoxLayout,QGridLayout)
- Qt使用布局管理器实现扩展对话框
- QT中的QGridLayout的使用
- 关于Qt-QGridLayout布局的简单使用
- qt4:lay.cpp 布局、信号、槽的综合使用
- Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
- Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
- Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
- 关于Qt-QGridLayout布局的简单使用
- Qt随笔 - QVBoxLayout和QHBoxLayout
- QT4:布局管理器的综合使用
- Qt之水平/垂直布局(QBoxLayout、QHBoxLayout、QVBoxLayout)
- Qt中使用QGridLayout 使QPushButton占两行
- QT学习记录(1)-控件 QPushButton, QLineEdit, QLabel, QHBoxLayout, QGridLayout
- IOS之UI--小实例项目--综合使用
- Qt绘 —— QPixmap 的使用
- Linux下移植pjsip,使用QT开发
- Qt-----使用QJson库