锋哥原创的PyQt6视频教程:
GroupBox控件又称为分组框控件,主要为其他控件提供分组,并且按照控件的分组来细分窗口的功能。
QGroupBox类的常用方法。
方法 | 说明 |
---|---|
setAlignment() | 设置对齐方式,包括水平对齐和垂直对齐两种水平对齐方式包括如下4种。 Qt.AlignLeft:左对齐; Qt.AlignHCenter:水平居中对齐; Qt.AlignRight:右对齐; Qt.AlignJustify:两端对齐; 垂直对齐方式包括如下3种。 Qt.AlignTop:顶部对齐; Qt.AlignVCenter:垂直居中; Qt.AlignBottom:底部对齐; |
setTitle() | 设置分组标题 |
setFlat() | 设置是否以扁平样式显示 |
UI生成参考代码:
python
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(663, 481)
self.groupBox = QtWidgets.QGroupBox(parent=Form)
self.groupBox.setGeometry(QtCore.QRect(40, 40, 241, 351))
self.groupBox.setAlignment(QtCore.Qt.AlignmentFlag.AlignBottom|QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing)
self.groupBox.setFlat(True)
self.groupBox.setCheckable(True)
self.groupBox.setObjectName("groupBox")
self.pushButton = QtWidgets.QPushButton(parent=self.groupBox)
self.pushButton.setGeometry(QtCore.QRect(50, 60, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(parent=self.groupBox)
self.pushButton_2.setGeometry(QtCore.QRect(50, 120, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(parent=self.groupBox)
self.pushButton_3.setGeometry(QtCore.QRect(50, 180, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.groupBox_2 = QtWidgets.QGroupBox(parent=Form)
self.groupBox_2.setGeometry(QtCore.QRect(350, 40, 261, 351))
self.groupBox_2.setObjectName("groupBox_2")
self.pushButton_4 = QtWidgets.QPushButton(parent=self.groupBox_2)
self.pushButton_4.setGeometry(QtCore.QRect(90, 50, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(parent=self.groupBox_2)
self.pushButton_5.setGeometry(QtCore.QRect(90, 110, 75, 23))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(parent=self.groupBox_2)
self.pushButton_6.setGeometry(QtCore.QRect(90, 170, 75, 23))
self.pushButton_6.setObjectName("pushButton_6")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.groupBox.setTitle(_translate("Form", "业务设置1"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "PushButton"))
self.pushButton_3.setText(_translate("Form", "PushButton"))
self.groupBox_2.setTitle(_translate("Form", "业务设置2"))
self.pushButton_4.setText(_translate("Form", "PushButton"))
self.pushButton_5.setText(_translate("Form", "PushButton"))
self.pushButton_6.setText(_translate("Form", "PushButton"))