ZetCode PyQt4 tutorial layout management
!/usr/bin/python
-*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows three labels on a window
using absolute positioning. 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): # The label widget is positioned at x=15 and y=10.
lbl1 = QtGui.QLabel('ZetCode', self)
lbl1.move(15, 10) lbl2 = QtGui.QLabel('tutorials', self)
lbl2.move(35, 40) lbl3 = QtGui.QLabel('for programmers', self)
lbl3.move(55, 70) self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Absolute')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main() -------------------------------------------------------------------------------- #!/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): # Here we create two push buttons.
okButton = QtGui.QPushButton("OK")
cancelButton = QtGui.QPushButton("Cancel") # 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.
hbox = QtGui.QHBoxLayout()
# Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end of this box layout.
# 添加一个弹簧,填充空间
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton) # 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.
vbox = QtGui.QVBoxLayout()
# 添加一个弹簧,填充空间
vbox.addStretch(1)
vbox.addLayout(hbox) # Finally, we set the main layout of the window.
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() -------------------------------------------------------------------------------- #!/usr/bin/python
# -*- coding: utf-8 -*- import sys
from PyQt4 import QtGui """
ZetCode PyQt4 tutorial In this example, we create a skeleton
of a calculator using a QtGui.QGridLayout. author: Jan Bodnar
website: zetcode.com
last edited: July 2014
""" class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): # The instance of a QtGui.QGridLayout is created and set to be the layout for the application window.
grid = QtGui.QGridLayout()
self.setLayout(grid) # These are the labels used later for buttons.
names = ['Cls', 'Bck', '', 'Close',
'', '', '', '/',
'', '', '', '*',
'', '', '', '-',
'', '.', '=', '+'] # We create a list of positions in the grid.
positions = [(i,j) for i in range(5) for j in range(4)] # Buttons are created and added to the layout with the addWidget() method.
for position, name in zip(positions, names): if name == '':
continue
button = QtGui.QPushButton(name)
grid.addWidget(button, *position) self.move(300, 150)
self.setWindowTitle('Calculator')
self.show() def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main() -------------------------------------------------------------------------------- #!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we create a bit
more complicated window layout using
the QtGui.QGridLayout manager. 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): title = QtGui.QLabel('Title')
author = QtGui.QLabel('Author')
review = QtGui.QLabel('Review') titleEdit = QtGui.QLineEdit()
authorEdit = QtGui.QLineEdit()
reviewEdit = QtGui.QTextEdit() # We create a grid layout and set spacing between widgets.
grid = QtGui.QGridLayout()
grid.setSpacing(10) grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1) grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1) grid.addWidget(review, 3, 0)
# If we add a widget to a grid, we can provide row span and column span of the widget. In our case, we make the reviewEdit widget span 5 rows.
grid.addWidget(reviewEdit, 3, 1, 5, 1) self.setLayout(grid) self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
ZetCode PyQt4 tutorial layout management的更多相关文章
- ZetCode PyQt4 tutorial Drag and Drop
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...
- ZetCode PyQt4 tutorial widgets II
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial widgets I
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial Dialogs
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial signals and slots
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window
!/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This program create ...
- ZetCode PyQt4 tutorial First programs
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial basic painting
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
随机推荐
- 028-B+树(一)
B+ 树 这部分主要学习:什么是B+树? 了解了 B 树后再来了解下它的变形版:B+ 树,它比 B 树的查询性能更高. 一棵 B+ 树需要满足以下条件: 节点的子树数和关键字数相同(B 树是关键字数比 ...
- EditPlus 4.3.2473 中文版已经发布(10月21日更新)
新的 EditPlus 修复了如下问题: * Ctrl+鼠标拖放文本功能异常 * 上传文件到 FTP 服务器失败后将弹出对话框,可重试上传 * 列选模式下粘贴到现存的选中内容时文本错乱的问题 本博客已 ...
- Java 动态代理是基于什么原理
动态代理 ①动态代理概念理解 动态代理是一种方便运行时动态构建代理.动态处理代理方法调用的机制,很多场景都利用类似机制做到的,比如用来包装RPC调用.面向切面的变成(AOP) 实现动态代理的方式很多, ...
- Java中com.jcraft.jsch.ChannelSftp讲解
http://blog.csdn.net/allen_zhao_2012/article/details/7941631 http://www.cnblogs.com/longyg/archive/2 ...
- SpringMVC中@pathVariable和@RequestParam注解的区别
@pathVariable和@RequestParam的区别 @pathVariable:是从路径中获取变量,也就是把路径当做变量 @RequestParam:是从请求里面获取参数 案例分析: /Sp ...
- Vue学习笔记之Vue的面向对象
0x00 准备工作 JavaScript 语言中,生成实例对象的传统方法是通过构造函数. function Animal(name,age){ this.name = name; this.age = ...
- Cooperation.GTST团队项目总结
Cooperation.GTST团队项目总结 项目实现情况 目前对于基本UI界面的设计已经实现,对博客园接口XML的解析也已经完成,但是还暂时无法动态获取对应数据. 几张静态预览图展示(侧滑栏设计加入 ...
- ngular6开发不完全笔记(二)-- 管道
自定义管道 管道(过滤器)为过滤数据显示下列list数据 pip.ts 文件 import { Pipe, PipeTransform } from '@angular/core'; import { ...
- 模块的封装之C语言类的封装
[微知识]模块的封装(一):C语言类的封装 是的,你没有看错,我们要讨论的是C语言而不是C++语言中类的封装.在展开知识点之前,我首先要 重申两点: 1.面向对象是一种思想,基本与所用的语言是无关的. ...
- 安装Git【转】
本文转载自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 最早Git是在Linu ...