Widgets can span multiple columns or rows in a grid. In the next example we illustrate this.

#!/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() 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)
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()

We create a window in which we have three labels, two line edits, and one text edit widget. The layout is done with the QtGui.QGridLayout.

grid = QtGui.QGridLayout()
grid.setSpacing(10)

We create a grid layout and set spacing between widgets.

grid.addWidget(reviewEdit, 3, 1, 5, 1)

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.

Figure: Review example

GridLayout with span的更多相关文章

  1. [Android]RecyclerView的简单演示样例

    去年google的IO上就展示了一个新的ListView.它就是RecyclerView. 下面是官方的说明,我英语能力有限,只是我大概这么理解:RecyclerView会比ListView更具有拓展 ...

  2. Android——GridLayout

    转载自http://www.cnblogs.com/over140/archive/2011/12/08/2280224.html 欢迎大家转载 前言 本章内容android.widget.GridL ...

  3. 02网格布局Gridlayout

    <span style="font-size:18px;"><?xml version="1.0" encoding="utf-8& ...

  4. CSS之div和span标签

    div和span是非常重要的标签,div的语义是division"分割": span的语义就是span"范围.跨度". 这两个东西,都是最最重要的"盒 ...

  5. 如何改变span元素的宽度与高度

    内联元素:也称为行内元素,当多个行内元素连续排列时,他们会显示在一行里面. 内联元素的特性:本身是无法设置宽度和高度属性的,但是可以通过CSS样式来控制,达到我们想要的宽度和高度. span举例1: ...

  6. GridLayout 使用

    上次做了一个小键盘,请见:PopupWindow 使用. 效果是这样的: 可以看到,上面的按键是不一样大小的.因为是用LinearLayout布局,用的Button样式也是默认的.数字键和文字键的大小 ...

  7. Android之TextView的样式类Span的使用详解

           Android中的TextView是个显示文字的的UI类,在现实中的需求中,文字有各式各样的样式,TextView本身没有属性去设置实现,我们可以通过Android提供的 Spannab ...

  8. 火狐下多个span连在一起和换行写存在差异

    当父元素的宽度确定,多个span换行写,span加起来占的宽度比预设的大

  9. IE下a标签后面的span元素向右浮动后错位

    错误原因span放在了a标签之后 正确写法是放在之前 如下: <li><span>2016-07-29</span><a href="#" ...

随机推荐

  1. HDU 1698 Just a Hook (线段树)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  2. 【贪心】【堆】Gym - 101485A - Assigning Workstations

    题意:有n个人,依次来到机房,给你他们每个人的到达时间和使用时间,你给他们分配电脑,要么新开一台, 要么给他一台别人用完以后没关的.一台电脑会在停止使用M分钟后自动关闭.让你最大化不需要新开电脑的总人 ...

  3. 【期望DP】BZOJ3450- Tyvj1952 Easy

    ---恢复内容开始--- [题目大意] 有n次点击要做,成功了就是o,失败了就是x,分数是按comb计算的,连续a个comb就有a*a分,comb就是极大的连续o.求期望分数. [思路] 比之前的OS ...

  4. [AtCoder-ARC073F]Many Moves

    题目大意: 有一排n个格子和2枚硬币. 现在有q次任务,每一次要你把其中一枚硬币移到x的位置上,移动1格的代价是1. 两枚硬币不能同时移动,任务必须按次序完成. 现在告诉你两枚硬币初始状态所在的位置a ...

  5. MySql默认编码所造成的乱码麻烦1.222

    1.前言 MySQL在安装时,最后的一步,会让你选择MySQL服务器及客户端.数据库.连接接口的默认编码.通常可选择 UTF8和GB2312. 但是,如果你选择了utf8的时候,恰好你要从另一个数据库 ...

  6. Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力

     A. Mike and Frog Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...

  7. Cocoapods报错Unable to satisfy the following requirements

    很多时候我们都会去gitHub上down别人的源码去研究,如果别人的项目用pod集成了,当我们下载好后不外乎cd到项目根目录pod install一下,集成项目所需的库类.今天在我pod instal ...

  8. 一个iframe注入漏洞,也是微软的 Application["error"] 漏洞

    最近学校进行安全等级评估,有人给我打电话,说我之前写的一个网站存在iframe注入漏洞,页面是error页面.我于是用netsparker扫描了自己的网站,果然发现error页面存在漏洞,我写网站的时 ...

  9. python模块整理29-redis模块

    date:20140530auth:jinhttp://github.com/andymccurdy/redis-pyhttps://github.com/andymccurdy/redis-py/b ...

  10. J-LINK序列号修改

    打开J-LINK   COMMANDER中输入 exec setsn=xxxxxxxx 即可