Michail Kon Asked:2020-09-08 20:14:39 +0800 CST2020-09-08 20:14:39 +0800 CST 2020-09-08 20:14:39 +0800 CST 从 PyQt5 中的 groupbox 获取标题 772 我正在使用PyQt5编写代码。我有一个groupbox名为“情感”的表格。我怎样才能得到当前title的groupbox? python 1 个回答 Voted Best Answer S. Nick 2020-09-08T20:38:16+08:002020-09-08T20:38:16+08:00 在这里阅读:https ://doc.qt.io/qt-5/qgroupbox.html#title-prop 标题:QString 此属性包含组框的标题文本。如果标题包含与符号 ('&') 后跟一个字母,则组框标题文本将具有键盘快捷键。 import sys from PyQt5 import QtWidgets class Window(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Window, self).__init__(parent) # creates a QGroupBox title = '&Emotion' qgroupbox = QtWidgets.QGroupBox(title) print( type(qgroupbox) ) print( "title -> {}".format(qgroupbox.title() ) ) # <--- # sets the margins left, top, right, bottom = 10, 10, 10, 10 self.setContentsMargins(left, top, right, bottom) # sets the QGroupBox as the central widget self.setCentralWidget(qgroupbox) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = Window() window.setWindowTitle('Create a QGroupBox with a title') window.resize(400, 400) window.show() sys.exit(app.exec_())
在这里阅读:https ://doc.qt.io/qt-5/qgroupbox.html#title-prop