PyQt5:网格布局(13)
来源:互联网 发布:父母干涉爱情知乎 编辑:程序博客网 时间:2024/05/16 12:07
学习《PyQt4入门指南 PDF中文版.pdf 》笔记
最通用的布局类别是网格布局(QGridLayout)。该布局方式将窗口空间划分为许多行和列。要创建该布局方式,我们需要实用QGridLayout类。
#!/usr/bin/python# gridlayout.pyfrom PyQt5.QtWidgets import QApplication, QPushButton, QLabel, QGridLayoutfrom PyQt5 import QtWidgetsclass GridLayout(QtWidgets.QWidget): def __init__(self, parent= None): QtWidgets.QWidget.__init__(self) self.setWindowTitle('grid layout') names = ['Cls', 'Bck','', 'Close', '7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', '0', '.', '=', '+'] grid = QGridLayout() j = 0 pos = [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1,), (2, 2), (2, 3), (3, 0), (3, 1,), (3, 2), (3, 3), (4, 0), (4, 1,), (4, 2), (4, 3),] for i in names: button = QPushButton(i) if j == 2: grid.addWidget(QLabel(''), 0, 2) else: grid.addWidget(button, pos[j][0], pos[j][1]) j = j + 1; self.setLayout(grid) self.resize(300, 150)if __name__ == "__main__": import sys app = QApplication(sys.argv) qb = GridLayout() qb.show() sys.exit(app.exec_())
在这个示例中,我们创建一组按照网格布局的按钮。为了填补Bck和Close按钮之间的空白,我们使用QLabel部件。
grid= QGridLayout()
该语句创建了一个网格布局。
if j == 2:
grid.addWidget(QLabel(''), 0, 2)
else:
grid.addWidget(button, pos[j][0], pos[j][1])
使用addWidget()方法,我们将部件加入到网格布局中。addWidget()方法的参数依次为要加入到局部的部件,行号和列号。
0 0
- PyQt5:网格布局(13)
- PyQt5:网格布局2(14)
- 源码讲解PyQt5的文本框与网格布局
- PyQt5初级教程--PyQt5中的布局管理[5/13]
- Eric6与pyqt5学习笔记 3【水平/垂直,网格,窗体四大类布局】
- 网格布局
- PyQt5:Box布局(12)
- PyQt5:表格布局(15)
- pyQt5-布局管理
- bootstrap布局:网格布局
- PyQt5教程-08-布局管理
- Java_GUI_布局_网格布局
- 网页布局--CSS网格布局
- Layout布局之网格布局
- 相对布局和网格布局
- 边界布局和网格布局
- SWT GridLayout 网格布局
- 网格布局 GridBagLayout()
- 关于构造函数继承的一些问题
- KMP算法 --->字符串
- Toast 显示提示信息
- 嵌入式 、linux驱动模块编译(初学者)
- 面试热门题:字符串左旋右旋
- PyQt5:网格布局(13)
- 求解爱因斯坦阶梯问题。
- 五. Ubuntu下安装 tftp 服务器和 NFS 服务器
- 谈谈我对Spring IOC与DI的理解
- 再谈SQL优化:组合索引
- android一些有用的网址
- 第7章 取消与关闭
- SICP 练习1.9
- 嵌入式Linux驱动开发之helloword心得