亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

python GUI庫圖形界面開發之PyQt5布局控件QGridLayout詳細使用方法與實例

瀏覽:53日期:2022-08-03 15:02:42
PyQt5布局控件QGridLayout簡介

QGridLayout(網格布局)是將窗口分割成行和列的網格來進行排列,通常可以使用函數addWidget()將被管理的控件(Widget)添加到窗口中,或者使用addLayout()函數將布局(layout)添加到窗口中,也可以通過addWIdget()函數對所添加的控件設置行數與列數的跨越,最后實現網格占據多個窗格

QGridLayout類中常用的方法 方法 描述 addWidget(QWidget Widget,int row,int col,int alignment=0) 給網格布局添加部件,設置指定的行和列,起始位置的默認值為(0,0) widget:所添加的控件 row:控件的行數,默認從0開始 column:控件的列數,默認從0開始 alignment:對齊方式 addWidget(QWidget widget,int fromRow,int fromColulmn,int rowSpan,int columnSpan,Qt.Alignment alignment=0) 所添加的的控件跨越很多行或者列的時候,使用這個函數 widget:所添加的控件 fromRow:控件的起始行數 fronColumn:控件的起始列數 rowSpan:控件跨越的行數 column:控件跨越的列數 alignment:對齊方式 setSpacing(int spacing) 設置軟件在水平和垂直方向的間隔 QGridLayout單一的網格單元格實例

import sysfrom PyQt5.QtWidgets import QApplication ,QWidget , QGridLayout, QPushButtonclass Winform(QWidget): def __init__(self,parent=None): super(Winform,self).__init__(parent) self.initUI() def initUI(self): #1創建QGridLayout的實例,并設置窗口的布局 grid = QGridLayout() self.setLayout(grid) #2創建按鈕的標簽列表 names = [’Cls’, ’Back’, ’’, ’Close’, ’7’, ’8’, ’9’, ’/’, ’4’, ’5’, ’6’, ’*’, ’1’, ’2’, ’3’, ’-’, ’0’, ’.’, ’=’, ’+’] #3 在網格中創建一個位置列表positions = [(i,j) for i in range(5) for j in range(4)] #4 創建按鈕并通過addWIdget()方法添加到布局中 for position, name in zip(positions, names): if name == ’’: continue button = QPushButton(name) grid.addWidget(button, *position) self.move(300, 150) self.setWindowTitle(’網格布局管理例子’) if __name__ == '__main__': app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

運行效果圖如下

python GUI庫圖形界面開發之PyQt5布局控件QGridLayout詳細使用方法與實例

第一組代碼:創建QGridLayout的實例,并設置窗口的布局

第二組代碼:創建按鈕的標簽列表

第三組代碼:在網格中創建一個位置列表

第四組代碼:創建按鈕并通過addWIdget()方法添加到布局中

QGridLayout跨越行和列的網格單元格實例

import sysfrom PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit, QTextEdit, QGridLayout, QApplication) class Winform(QWidget): def __init__(self,parent=None): super(Winform,self).__init__(parent) self.initUI() def initUI(self): titleLabel = QLabel(’標題’) authorLabel = QLabel(’提交人’) contentLabel = QLabel(’申告內容’) titleEdit = QLineEdit() authorEdit = QLineEdit() contentEdit = QTextEdit() grid = QGridLayout() grid.setSpacing(10) grid.addWidget(titleLabel, 1, 0) grid.addWidget(titleEdit, 1, 1) grid.addWidget(authorLabel, 2, 0) grid.addWidget(authorEdit, 2, 1) grid.addWidget(contentLabel, 3, 0) grid.addWidget(contentEdit, 3, 1, 5, 1) self.setLayout(grid) self.setGeometry(300, 300, 350, 300) self.setWindowTitle(’故障申告’)if __name__ == '__main__': app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

運行效果示意圖如下

python GUI庫圖形界面開發之PyQt5布局控件QGridLayout詳細使用方法與實例

代碼分析

把titleLabel放在QGridLayout布局的第一行第0列

grid.addWidget(titleLabel, 1, 0)  

把titleEditl放在QGridLayout布局的第一行第1列

grid.addWidget(titleEdit, 1, 1)  

把contentLabel放在QGridLayout布局的第3行第0列

grid.addWidget(contentLabel, 3, 0)  

把contentEdit放在QGridLayout布局的第3行第1列,跨越5行1列

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

本文主要介紹了PyQt5布局控件QGridLayout詳細使用方法與實例,更多關于PyQt5布局控件知識請查看下面的相關鏈接

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 日韩色视频一区二区三区亚洲 | 国产精选一区二区 | 色综合久久久久久久 | 成人影院久久久久久影院 | 亚洲精品一区二区三区中文字幕 | 国产成人免费在线 | 生活片毛片 | 亚洲国产精品久久久天堂 | 免费人成黄页网站在线观看国产 | 全部孕妇毛片丰满孕妇孕交 | 国产视频亚洲 | 在线欧美一级毛片免费观看 | 一级一毛片a级毛片欧美 | 久久se精品一区精品二区 | 日本aaa视频 | 欧美成人在线视频 | 日本b站一卡二不卡 | a毛片在线看片免费 | 俺来也欧美亚洲a∨在线 | 99久久精品免费看国产免费软件 | 欧美综合自拍亚洲综合 | 欧美精品一区二区三区免费播放 | 国产不卡视频在线观看 | 欧美日韩一区二区三区久久 | 最新理论三级中文在线观看 | 韩日毛片 | 操操综合网| 欧美精品久久天天躁 | 亚洲在线观看视频 | 国产精品久久久久久一级毛片 | 免费播放国产性色生活片 | 男人添女人下面免费毛片 | 一级欧美激情毛片 | 国产精品久久毛片蜜月 | 99re7在线精品免费视频 | 91无套极品外围在线播放 | 欧美一区二区日韩一区二区 | 国产成人影院一区二区 | 国产三级毛片 | 精品一区二区在线欧美日韩 | 亚洲一区免费在线观看 |