1

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)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
kashmoney
  • 412
  • 1
  • 5
  • 17

2 Answers2

1

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")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks for this, I am additionally trying to pass along the name of a file that the user uploads to another page in the wizard, but cannot seem to find the right way of doing this in the documentation. For example I have something like file_name = QtWidgets.QFileDialog(self).getOpenFileName(self.uploader), but this returns a tuple, and when I try and get just the path using tuple[0], and attempting to pass it along as a string using " temp = QtWidgets.QLabel(file_name[0]) self.registerField("file_name",temp) I will get a no such field "file_name" error. – kashmoney Jul 10 '18 at 19:17
  • @kashmoney without a [mcve] I could not tell you where the error is – eyllanesc Jul 10 '18 at 20:19
  • I figured it would be easier to just make a new question on this so I wrote it here (https://stackoverflow.com/questions/51273301/pyqt-trouble-passing-filenames-across-qwizardpage) – kashmoney Jul 10 '18 at 20:28
0

been looking for this answer for a while, since the registerField() takes a property as a parameter.

in your wizard you can set a custom property for example if you were to use a table widget of some sort that doesn't have get functionality built in to bulk get the whole table.

so you can do something like this


class SplitWizardPage(QWizardPage):
    def __init__(self, table_data, table_headers):
        super().__init__()

        self.table_data = table_data
        self.table_headers = table_headers

        self.table_widget = QTableWidget()
        self.table_widget.setProperty("mutated_table_data", [])

...

def on_cell_changed(self, row, column):
     ...some get data code
     self.table_widget.setProperty("mutated_table_data", table_data)

...

finally 

        self.table_widget.cellChanged.connect(lambda: on_cell_changed(self, row, column))

        self.registerField("split_table_data", self.table_widget, "mutated_table_data", self.table_widget.cellChanged)

finally.

wizard.finished.connect(lambda: print(wizard.field("split_table_data")))

as you can see we are attaching it to the property 'mutated_table_data' on the widget field

Fanna1119
  • 1,878
  • 4
  • 24
  • 30