【发布时间】:2018-01-15 19:44:54
【问题描述】:
我正在尝试编写一个 QGIS 插件并使用 python 3 和 Qt5 显示一个帮助对话框。但是,基于QDialogButtonBox 的默认对话框只显示两个标准按钮,没有文字。
.ui 文件包含以下内容:
<widget class="QDialogButtonBox" name="button_box" >
<property name="geometry" >
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
我是 Qt5/pyqt 的新手。我尝试在以下示例中添加一个小部件:
label = QLabel()
label.setText("Help\n instructions: \n")
self.dlg.addWidget(label)
但我收到一个错误:AttributeError: 'XXXDialog' object has no attribute 'addWidget'
我的问题是:
如何添加QLabel 或另一个可以在对话框的主要区域显示多行文本的小部件(最好使用文本编辑器)。我必须使用与QDialogButtonBox 不同的基类吗?
【问题讨论】:
-
你为什么不直接关注QGIS Plugin Tutorial?它以简单的步骤引导您完成整个过程,包括使用 Qt Creator 设计 gui。
标签: python pyqt pyqt5 qlabel qdialog