pyside2 groupbox_map2 获取标题
时间: 2023-08-03 22:06:40 浏览: 45
在PySide2中,可以通过groupBox.title()方法获取QGroupBox的标题。以下是一个示例代码:
```python
from PySide2.QtWidgets import QWidget, QGroupBox, QVBoxLayout, QApplication, QLabel
class MyClass(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
# create a group box with title "My Group Box"
group_box = QGroupBox("My Group Box", self)
# create a label with the title of group box
title_label = QLabel(group_box.title(), self)
# add the label to the layout of widget
layout = QVBoxLayout(self)
layout.addWidget(title_label)
if __name__ == '__main__':
app = QApplication([])
window = MyClass()
window.show()
app.exec_()
```
在上述代码中,我们创建了一个名为group_box的QGroupBox对象,并将其标题设置为“My Group Box”。然后,我们创建了一个名为title_label的QLabel对象,并将QGroupBox的标题设置为QLabel的文本。最后,我们将QLabel添加到QWidget的布局中,并显示QWidget。运行该代码后,我们将看到一个包含标题“My Group Box”的标签。