I am trying to create a Wizard using PyQt5 and I'm trying to make it so that the input entered by the user on one page influences what the user will see on the next page. However, when I try and do so, I only see the index value as opposed to the text.
Creating a list and then mapping the index value to the appropriate location in the list in order to get the string seems a bit janky, so does anyone know if PyQt has a better function built-in that does this?
class IntroductionPage(QtWidgets.QWizardPage):
def __init__(self,*args,**kwargs):
super().__init__()
self.setTitle("Project Name")
self.setSubTitle("Please select one of the available projects below")
l = get_projects()
comboBox = QtWidgets.QComboBox(self)
[comboBox.addItem(i) for i in l]
layout = QtWidgets.QGridLayout()
layout.addWidget(comboBox)
self.setLayout(layout)
self.registerField("projectName",comboBox)
class TaskPage(QtWidgets.QWizardPage):
def __init__(self,*args,**kwargs):
super().__init__()
# currently returns an integer and not a string
def initializePage(self):
self.setTitle(self.field("projectName"))
class My_Wizard(QtWidgets.QWizard):
num_of_pages = 2
(intro,task) = range(num_of_pages)
def __init__(self,*args,**kwargs):
super(My_Wizard,self).__init__(*args,**kwargs)
self.setPage(self.intro,IntroductionPage(self))
self.setPage(self.task,TaskPage(self))
self.setStartId(self.intro)
The registerField()
method has more parameters:
void QWizardPage::registerField(const QString &name, QWidget *widget, const char *property = nullptr, const char *changedSignal = nullptr)
So the solution is to indicate that you want to get the currentText
property of the QComboBox
:
self.registerField("projectName", comboBox, "currentText")