Box layout
Layout management with layout classes is much more flexible and practical. It is the preferred way to place widgets on a window. The QtGui.QHBoxLayout
and QtGui.QVBoxLayout
are basic layout classes that line up widgets horizontally and vertically.
Imagine that we wanted to place two buttons in the right bottom corner. To create such a layout, we will use one horizontal, and one vertical box. To create the necessary space, we will add a stretch factor.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we position two push
buttons in the bottom-right corner
of the window. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): okButton = QtGui.QPushButton("OK")
cancelButton = QtGui.QPushButton("Cancel") hbox = QtGui.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton) vbox = QtGui.QVBoxLayout()
vbox.addStretch(1)
vbox.addLayout(hbox) self.setLayout(vbox) self.setGeometry(300, 300, 300, 150)
self.setWindowTitle('Buttons')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
The example places two buttons in the bottom-right corner of the window. They stay there when we resize the application window. We use both a QtGui.HBoxLayout
and a QtGui.QVBoxLayout
.
okButton = QtGui.QPushButton("OK")
cancelButton = QtGui.QPushButton("Cancel")
Here we create two push buttons.
hbox = QtGui.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton)
We create a horizontal box layout and add a stretch factor and both buttons. The stretch adds a stretchable space before the two buttons. This will push them to the right of the window.
vbox = QtGui.QVBoxLayout()
vbox.addStretch(1)
vbox.addLayout(hbox)
To create the necessary layout, we put a horizontal layout into a vertical one. The stretch factor in the vertical box will push the horizontal box with the buttons to the bottom of the window.
self.setLayout(vbox)
Finally, we set the main layout of the window.
Figure: Buttons
Box layout的更多相关文章
- Layout( 布局)
一. 加载方式//class 加载方式<div id="box" class="easyui-layout"style="width:600px ...
- Box布局
import sys from PyQt4 import QtCore, QtGui class MainWindow(QtGui.QWidget): def __init__(self, paren ...
- PyQt4 Box布局
使用布局类别方式的布局管理器比绝对方式的布局管理器更加灵活实用.它是窗口部件的首选布局管理方式.最基本的布局类别是QHBoxLayout和QVBoxLayout布局管理方式,分别将窗口部件水平和垂直排 ...
- ZetCode PyQt4 tutorial layout management
!/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...
- PyQt的Layout的比例化分块。
一. QGridLayout: // 列比 第0列与第1列之比为 1:2 layout2p1 -> setColumnStretch(0, 1); layout2p1 -> setColu ...
- 第二百零二节,jQuery EasyUI,Layout(布局)组件
jQuery EasyUI,Layout(布局)组件 学习要点: 1.加载方式 2.布局属性 3.区域面板属性 4.方法列表 本节课重点了解 EasyUI 中 Layout(布局)组件的使用方法,这个 ...
- layout(布局)组件
一.依赖于 Panel(面 板)组件和 resizable(调整大小)组件. 二.class加载方式 <div id="box" class="easyui- ...
- CSS3 弹性盒子(Flex Box)
1 CSS3 弹性盒子(Flex Box) 1 http://caniuse.com/#search=flex%20box https://www.w3.org/TR/css-flexbox-1/ C ...
- CSS ? Layout Module : CSS 布局模型
1 1 1 https://www.w3.org/TR/css-grid-1/ CSS Grid Layout Module Level 1 W3C Working Draft, 19 May 201 ...
随机推荐
- wpf企业应用之UI模块解耦
关于UI模块的解耦,说简单点,首先需要配置菜单与对应操作类的映射关系(或存放于配置文件,或继承接口直接写死在模块代码中,或存放到数据库,原理都一样),然后在菜单加载时,读取配置项动态生成菜单或是其他控 ...
- [BZOJ4539][HNOI2016]树(主席树)
4539: [Hnoi2016]树 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 746 Solved: 292[Submit][Status][D ...
- POJ2185 Milking Grid KMP两次(二维KMP)较难
http://poj.org/problem?id=2185 大概算是我学KMP简单题以来最废脑子的KMP题目了 , 当然细节并不是那么多 , 还是码起来很舒服的 , 题目中描写的平铺是那种瓷砖一 ...
- 所以学树分块的时候为什么要看vector啊sjb
明明应该拼命刷题却悠哉补着vector和指针 -------------------------------------------------------------------题记 http:// ...
- CAShapeLayer实现音量大小动态改变
我是效果图 实现如图这效果一般会直接通过多张图进行切换进行完成.但这样的处理,会浪费App的资源存储空间,而且效率也不高.那么今天我们用CAShapeLayer实现以下吧. 拆分: 1.一个椭圆 2. ...
- XuLA/XuLA2
http://www.xess.com/prods/prod048.php XuLA http://www.xess.com/prods/prod055.php XuLA2 http://www.xe ...
- 小程序setData工作原理理解图
优化建议:1.频繁的去setData--我曾经用这个弄过动画效果,当然后来发现JS动画不适合小程序,CSS3动画才是王道2.每次setData都传递大量新数据--这个大量还真不好理解,暂时定为排行榜类 ...
- java.lang.RuntimeException: java.io.IOException: invalid constant type: 15
java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 controller通过dubbo调用servic ...
- ice地址
http://www.zeroc.com/download/eclipse
- ecside 列表排序问题
ecside列表首先点击某一列排序,没有问题,再点第二列的时候没有起作用.原因是第二次排序的时候还包含着第一次排序的字段.所以排序始终是第一次的排序结果. 修改ecside.js 的ECSideUti ...