import sys, math
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
"""
设置控件的对齐方式
"""
class HBoxLayoutAlign(QWidget):
def __init__(self):
super(HBoxLayoutAlign, self).__init__()
self.setWindowTitle("水平盒布局")
hbox_layout = QHBoxLayout()
hbox_layout.addWidget(QPushButton("按钮A"), 1, Qt.AlignLeft|Qt.AlignTop)
hbox_layout.addWidget(QPushButton("按钮B"), 1, Qt.AlignLeft|Qt.AlignTop)
hbox_layout.addWidget(QPushButton("按钮C"), 1, Qt.AlignLeft|Qt.AlignTop)
hbox_layout.addWidget(QPushButton("按钮D"), 1, Qt.AlignLeft|Qt.AlignBottom)
hbox_layout.addWidget(QPushButton("按钮E"), 1, Qt.AlignLeft|Qt.AlignBottom)
hbox_layout.addWidget(QPushButton("按钮F"), 1, Qt.AlignLeft|Qt.AlignBottom)
hbox_layout.setSpacing(30)
self.setLayout(hbox_layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = HBoxLayoutAlign()
win.show()
sys.exit(app.exec_())
|