I'm trying to create a mandatory QgsFileWidget
in a QWizard
form for a plugin but the result is a Next button that doesn't get active when I choose the path to save the project. Here is the snippet of the code:
import os
from PyQt5.QtWidgets import QWizard, QWizardPage
from qgis.PyQt import uic
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'plugin_wizard_base.ui'))
class PluginDialog(QWizard, QWizardPage, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
super(PluginDialog, self).__init__(parent)
self.setupUi(self)
try:
self.wizardPage.registerField('projPath*', self.projPath, self.projPath.filePath(), 'fileChanged')
except TypeError:
self.wizardPage.registerField('projPath*', self.projPath, self.projPath.filePath(), self.projPath.fileChanged)
This code works with a QLineEdit
perfectly, the only difference is the method to retrieve the path string and the signal (.text()
instead .filePath()
and .textChanged
instead .fileChanged
).
I've tried searching in the documentation but I didn't find an example specifically for QgsFileWidget
. I feel that is a minor detail I've been missing. Any suggestions?
I'm using PyQt5 with Qt Designer to generate the GUI for the plugin.
Update:
I replaced the code as follows:
...
self.setupUi(self)
self.wizardPage.registerField('projPath*', self.projPath, 'filePath', self.projPath.fileChanged)
self.projPath.fileChanged.connect(self.file_changed)
def file_changed(self):
self.setField("projPath", self.projPath.filePath())
def isComplete(self): # Re-implementation of isComplete
return bool(self.projPath.filePath())
But the result was that the next button get unlocked only if I type the path directly in the text field. It doesn't work if I choose a path in the explorer dialog. Even so, after unlock the button, if I clean the field, the button remain active.