我正在关注 a 上的教程许可证向导 http://doc.qt.io/qt-5/qtwidgets-dialogs-licensewizard-example.html (using PyQt5
)尝试学习如何创建非线性向导。然而我似乎陷入了一个问题。
我想要一个页面QComboBox
其中所选项目确定当前是否QWizardPage
包含组合框的页面是否为最终页面。
以下是该页面迄今为止包含的内容:
class CalibrationPageSource(QWizardPage):
def __init__(self, parent):
super(CalibrationPageSource, self).__init__(parent)
self.setTitle('Calibration Wizard')
self.setSubTitle('Select the source for the calibration')
layout = QVBoxLayout()
label = QLabel('''
<ul>
<li><b>From calibration file</b>: browse and select an existing YAML calibration file that contains the camera matrix and distortion coefficients (for example from a previous calibration)</li>
<li><b>From image files</b>: browse and select one or more image files with the calibration pattern visible inside each</li>
<li><b>From stream</b> - if the calibration node is connected to an active <b><i>Device node</i></b> you can use its image stream to interactively calibrate your device</li>
</ul>
''')
label.setWordWrap(True)
layout.addWidget(label)
layout_sources = QHBoxLayout()
label_sources = QLabel('Source:')
self.selection_sources = QComboBox()
self.selection_sources.addItem('Calibration file')
self.selection_sources.addItem('Image files')
self.selection_sources.addItem('Stream')
self.selection_sources.currentIndexChanged['QString'].connect(self.source_changed)
self.selection_sources.setCurrentIndex(1)
layout_sources.addWidget(label_sources)
layout_sources.addWidget(self.selection_sources)
layout.addLayout(layout_sources)
self.setLayout(layout)
@pyqtSlot(str)
def source_changed(self, source):
if source == 'Calibration file':
self.setFinalPage(True)
# TODO Add file dialog
else:
self.setFinalPage(False)
# TODO Remove file dialog (if present)
每当self.selection_sources
的当前项目更改为Calibration file
我想跳过使页面最终确定的向导的其余部分。在这种情况下我想删除Next
按钮。在所有其他情况下(目前只有两种:Image files
and Stream
)我想让向导正常工作,而不是作为最终页面。
我尝试过实施自定义isComplete(...)
但问题是它同时禁用了Next
and Finish
when Calibration file
被选中。我可以忍受有残疾人Next
按钮(而不是完全隐藏它)但被禁用Finish
对我来说基本上没有意义。我实际上很惊讶Next
按钮存在。当到达最后一页时,它不是应该完全消失吗?
有什么想法如何解决这个问题吗?我考虑过迭代中的项目QWizardPage
并手动禁用/隐藏Next
按钮,但我希望有一种更简单、开箱即用的方法来做到这一点。在当前状态下动态插入Finish
正在工作,但是由于Next
按钮向导的转换未正确设置。
这已经晚了将近一年,但我想我已经弄清楚问题出在哪里了。您致电setFinalPage(True)
,只需在您的QWizardPage
。它不会自动传播回您的QWizard
.
只有一个信号可以传播信息:completeChanged https://doc.qt.io/qt-5/qwizardpage.html#completeChanged。这个名称有点误导,但文档似乎表明,如果您正确阅读它们,它就会执行您想要的操作:
如果你重新实现isComplete()
,确保发出completeChanged()
每当值isComplete()
变化,以确保QWizard
更新其按钮的启用或禁用状态。
事实上,遇到同样的问题,我能够通过这样做来解决它
if source == 'Calibration file':
self.setFinalPage(True)
...
else:
self.setFinalPage(False)
...
self.completeChanged.emit()
粗体线是新的。在这两种情况下都需要调用它,并且当您选择不同的选项时,会将按钮从“下一步”切换到“完成”并返回。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)