av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:109日期:2022-08-03 15:30:20
PyQt5布局控件QHBoxLayout簡介

采用QBOXLayout類可以在水平和垂直方向上排列控件,QHBoxLayout和QVBoxLayout類繼承自QBoxLayout

采用QHBoxLayout類,按照從左到右的順序來添加控件

QHBoxLayout類中常用的方法如下 方法 描述 addLayout(self,stretch=0) 在窗口的右邊添加布局,使用stretch(伸縮量)進行伸縮,伸縮量默認為0 addWidget(self,QWidget.stretch,Qt.Alignmeny alihnment) 在布局中添加控件 stretch(伸縮量),只適用于QBoxLayout,控件和窗口會隨著伸縮量的變大而增大 alignment:指定的對齊方式 addSpacing(self,int) 設置各控件的上下間距,通過該方法可以增加額外的控件 QHBoxLayout對齊方式參數 參數 描述 Qt.AlignLeft 水平方向居左對齊 Qt.AlignRight水平方向具有對齊 Qt.AlignCenter 水平方向居中對齊 Qt.AlignJustify 水平方向兩端對齊 Qt.AlignTop 垂直方向靠上對齊 Qt.AlignBottom 垂直方向靠下對齊 Qt.AlignVCenter 垂直方向居中對齊 QHBoxLayout水平布局管理實例

import sysfrom PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButtonclass Winform(QWidget): def __init__(self,parent=None): super(Winform,self).__init__(parent) self.setWindowTitle('水平布局管理例子') # 水平布局按照從左到右的順序進行添加按鈕部件。 hlayout = QHBoxLayout()hlayout.addWidget( QPushButton(str(1))) hlayout.addWidget( QPushButton(str(2))) hlayout.addWidget( QPushButton(str(3))) hlayout.addWidget( QPushButton(str(4)))hlayout.addWidget( QPushButton(str(5)))# todo 優化1 設置控件間距 #hlayout.setSpacing(20) self.setLayout(hlayout) if __name__ == '__main__': app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

運行效果圖

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

優化一:設置各控件之間的間距

hlayout.setSpacing(20)

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

QHBoxLayout水平布局對齊方式實例

在某些情況下,需要將布局中的某些控件居中,俱下顯示,那么可以通過對齊方式參數Qt.Alignment來設置,示范如下

import sysfrom PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButtonfrom PyQt5.QtCore import Qt class Winform(QWidget): def __init__(self,parent=None): super(Winform,self).__init__(parent) self.setWindowTitle('水平布局管理例子') self.resize(800, 200) # 水平布局按照從左到右的順序進行添加按鈕部件。 hlayout = QHBoxLayout() #水平居左 垂直居上 hlayout.addWidget( QPushButton(str(1)) , 0 , Qt.AlignLeft | Qt.AlignTop) hlayout.addWidget( QPushButton(str(2)) , 0 , Qt.AlignLeft | Qt.AlignTop) hlayout.addWidget( QPushButton(str(3))) #水平居左 垂直居下 hlayout.addWidget( QPushButton(str(4)) , 0 , Qt.AlignLeft | Qt.AlignBottom )hlayout.addWidget( QPushButton(str(5)), 0 , Qt.AlignLeft | Qt.AlignBottom) self.setLayout(hlayout) if __name__ == '__main__': app = QApplication(sys.argv) form = Winform() form.show() sys.exit(app.exec_())

運行效果圖如下

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

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

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产乱一区二区三区视频 | 91精品一区二区三区久久久久 | 91视频入口 | 国产精品a久久久久 | 欧美一区二区在线观看视频 | 国产高清在线精品 | 中文字幕日韩专区 | 国产亚洲一区二区三区 | 91久久| 国产真实乱全部视频 | 国产一区日韩在线 | 午夜久久久久 | 成人在线观看免费 | 99国内精品 | 国产精品v | 偷拍自拍网| 国外成人在线视频网站 | 中文字幕一区在线观看视频 | av性色全交蜜桃成熟时 | 婷婷午夜天 | 国产成人免费在线 | 精品国产不卡一区二区三区 | 日韩精品一区二区三区四区 | 黄篇网址 | 91一区二区在线观看 | 欧美激情在线精品一区二区三区 | 麻豆久久精品 | 日韩中文在线视频 | 99re热精品视频国产免费 | 中文字幕在线一 | 免费h在线 | 免费观看羞羞视频网站 | 日韩精品视频中文字幕 | 亚洲精品v| 在线成人福利 | 中文字幕第49页 | 成人免费在线电影 | 91精品国产综合久久香蕉922 | 欧美日韩成人在线 | 成人毛片在线视频 | 国产在线一区二区三区 |