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 sys
from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
class Winform(QWidget):
def __init__(self,parent=None):
super(Winform,self).__init__(parent)
self.setWindowTitle("水平布局管理例子"