Qt布局管理使用
2013-04-27 21:48
519 查看
1.使用类
使用的类无非就是四个类QHBoxLayout, QVBoxLayout, QGridLayout, QFormLayout,
一般情况使用如下接口就够了:
addLayout(QLayout *layout, int stretch)
addWidget(QWidget *widget, int stretch)
addSpacing(int size),// 增加一个固定大小的项(占一个位置)
addStretch(int stretch = 0),// 增加一个长度可增加的项(占一个位置) ,当增加这个以后,这行其它的widget,layout大小都会变为其sizeHint或者minimumsize,其它空间都被这个stretch占有(没有其它stretch)
(这两个都是addSpacerItem(QSpacerItem *spacerItem) 的简便函数.只是QSpacerItem的QSizePolicy不同而已)
setSpacing(int) // 各个控件间的空间
setContentsMargins(); // 边际到布局的空间
其它控件接口:
setSizeContraint(SizeContraint)
QSpacerItem的QSizePolicy:
2. 何时布局重新布局
1.QWidget发生一个QResizeEvent,
2.QApplicationPrivate::notify_helper中,判断是否安装有布局,
3.如有则调用layout->widgetEvent(e);最终调用QLayout::setGeometry()将布局排好位置
(QApplicationPrivate::notify_helper->QLayout::widgetEvent->QLayoutPrivate::doResize->QBoxLayout::setGeometry)
3.快速开发中使用Ui Designer已经绰绰有余, 需要自定义窗口类我的使用四个布局类再加位置编码组合解决大部分问题, 至于自定义布局一般情况用不上.
3.布局实现过程
(1)布局中项由QBoxLayoutItem封装,
(2)布局内部项使用QList<QBoxLayoutItem> list存储.
(3)在QLayout::setGeometry()中, 根据各个参数计算出项的QRect,设置位置
(4)要使用好布局类, 就要对控件的minimum, maxinmum, sizehint, sizepolicy都有充分的了解.
使用的类无非就是四个类QHBoxLayout, QVBoxLayout, QGridLayout, QFormLayout,
一般情况使用如下接口就够了:
addLayout(QLayout *layout, int stretch)
addWidget(QWidget *widget, int stretch)
addSpacing(int size),// 增加一个固定大小的项(占一个位置)
addStretch(int stretch = 0),// 增加一个长度可增加的项(占一个位置) ,当增加这个以后,这行其它的widget,layout大小都会变为其sizeHint或者minimumsize,其它空间都被这个stretch占有(没有其它stretch)
(这两个都是addSpacerItem(QSpacerItem *spacerItem) 的简便函数.只是QSpacerItem的QSizePolicy不同而已)
setSpacing(int) // 各个控件间的空间
setContentsMargins(); // 边际到布局的空间
其它控件接口:
setSizeContraint(SizeContraint)
Constant | Value | Description |
---|---|---|
QLayout::SetDefaultConstraint | 0 | The main widget's minimum size is set to minimumSize(), unless the widget already has a minimum size. |
QLayout::SetFixedSize | 3 | The main widget's size is set to sizeHint(); it cannot be resized at all. |
QLayout::SetMinimumSize | 2 | The main widget's minimum size is set to minimumSize(); it cannot be smaller. |
QLayout::SetMaximumSize | 4 | The main widget's maximum size is set to maximumSize(); it cannot be larger. |
QLayout::SetMinAndMaxSize | 5 | The main widget's minimum size is set to minimumSize() and its maximum size is set to maximumSize(). |
QLayout::SetNoConstraint | 1 | The widget is not constrained. |
Constant | Value | Description |
---|---|---|
QSizePolicy::Fixed | 0 | The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button). |
QSizePolicy::Minimum | GrowFlag | The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint(). |
QSizePolicy::Maximum | ShrinkFlag | The sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint(). |
QSizePolicy::Preferred | GrowFlag | ShrinkFlag | The sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy). |
QSizePolicy::Expanding | GrowFlag | ShrinkFlag | ExpandFlag | The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider). |
QSizePolicy::MinimumExpanding | GrowFlag | ExpandFlag | The sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider). |
QSizePolicy::Ignored | ShrinkFlag | GrowFlag | IgnoreFlag | The sizeHint() is ignored. The widget will get as much space as possible. |
1.QWidget发生一个QResizeEvent,
2.QApplicationPrivate::notify_helper中,判断是否安装有布局,
3.如有则调用layout->widgetEvent(e);最终调用QLayout::setGeometry()将布局排好位置
(QApplicationPrivate::notify_helper->QLayout::widgetEvent->QLayoutPrivate::doResize->QBoxLayout::setGeometry)
3.快速开发中使用Ui Designer已经绰绰有余, 需要自定义窗口类我的使用四个布局类再加位置编码组合解决大部分问题, 至于自定义布局一般情况用不上.
3.布局实现过程
(1)布局中项由QBoxLayoutItem封装,
(2)布局内部项使用QList<QBoxLayoutItem> list存储.
(3)在QLayout::setGeometry()中, 根据各个参数计算出项的QRect,设置位置
(4)要使用好布局类, 就要对控件的minimum, maxinmum, sizehint, sizepolicy都有充分的了解.
相关文章推荐
- Qt学习:布局管理的使用方法
- Qt布局管理之边栏及背景颜色和图片的设置
- Qt之布局管理——(1)基本布局管理
- Qt 第6章 布局管理(1) 在窗体中摆放窗口部件 学习笔记
- Qt学习记录4——mainwindow的布局使用
- 组合使用QT的资源管理高级功能简化开发过程
- 关于Qt-QGridLayout布局的简单使用
- Qt5布局管理(二)——QDockWidget停靠窗口类
- Qt布局之管理
- Qt布局管理: 停靠窗口QDockWidget类(纯代码实现)
- C++ GUI QT 第4版 第六章 布局管理 (3)
- Silverlight 教程第二部分:使用布局管理
- QT 布局管理
- Qt之布局管理——停靠窗口
- Android-布局管理 (五大布局控件使用)
- qt使用布局进行窗口切换
- QT实现竖直方向的窗口布局(使用QLayout类)
- Qt学习07——布局管理
- Qt 实现基本布局管理 ---实验
- atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform