Jeroj82
Jeroj82

Reputation: 401

PyQt5 double spin box returning none value

I have this: (there are class methods, which inherience from QWizard)

def getForms(self):
    return [
        (
            QtWidgets.QLabel("Name"),
            QtWidgets.QLineEdit()
        ),
        (
            QtWidgets.QLabel("Roll"),
            QtWidgets.QDoubleSpinBox()
        )
    ]

def registerFields(self, page, forms):
    page.registerField("name*", forms[0][1])
    page.registerField("roll", forms[1][1])

And in other place in code

id = self.currentId()
    if id == 1:
        print self.field("name") # this rightly give me a name from LineEdit
        print self.field("roll") # but this give me just None, why?

When I changed

QtWidgets.QDoubleSpinBox()

to

QtWidgets.QSpinBox()

Line:

print self.field("roll")

works fine.

Why do I get None instead double value?

EDIT

I've just noticed that when I'm trying make 'roll' field as a mandatory.

page.registerField("roll*", forms[1][1])

And I fill this 'spinbox' in program, I can not click 'next' (next is disabled). I have spinbox in my form in program. I can set the value there. But this looks like this field is not connected with QWizard(?)?

Upvotes: 1

Views: 751

Answers (1)

three_pineapples
three_pineapples

Reputation: 11849

The QWizardPage class only has internal knowledge of a few widget types. When registering a widget it does not know about, you need to specify the property for reading the value, along with the signal that is emitted when a value is changed, as a string.

For QDoubleSpinBox this would be:

page.registerField("roll", forms[1][1], "value", "valueChanged")

The list of widget types QWizardPage knows about is listed in the c++ documentation here.

You can also register this information globally using a method of QWizard, so that you don't have to specify it each time you call registerField(). To do this, call:

my_wizard.setDefaultProperty("QDoubleSpinBox", "value", "valueChanged")

Note: This is a method of the wizard, not the page.

Upvotes: 2

Related Questions