1

I am trying to use QWizard::validateCurrentPage from PySide. My wizard class is loaded from .ui file using PySide.QtUiTools.QUiLoader

I created a function that supposed to override build-in QWizard::validateCurrentPage:

def validateDataPage(self):
    return False

Now I am trying to override build-in method like this:

    self.wizard = uiloader.load("registrationwizard.ui")
    f = types.MethodType(validateDataPage, 
                         self.wizard, 
                         QtGui.QWizard)
    self.wizard.validateCurrentPage = f

I see in debugger that validateCurrentPage is replaced:

self.wizard.validateCurrentPage
<bound method QWizard.validateDataPage of <PySide.QtGui.QWizard object at 0x04CC31C0>>

I can call it from debugger, but it is not called when I click "next" page.

Am I doing something wrong of it is not possible to override virtual functions when object is already constructed?

Lukasz
  • 185
  • 1
  • 10

1 Answers1

0

I'm pretty sure it should work since your way is the canonical way for Adding a Method to an Existing Object in Python.

I made a small example and it seems to work for me.

import types
from PySide import QtGui

def overload(self):
    print(self.validateCurrentPage)
    return False

app = QtGui.QApplication([])
wizard = QtGui.QWizard()
wizard.validateCurrentPage = types.MethodType(overload, wizard)
wizard.addPage(QtGui.QWizardPage())
wizard.addPage(QtGui.QWizardPage())
wizard.show()
app.exec_()

prints

<bound method QWizard.overload of <PySide.QtGui.QWizard object at xx>>
Community
  • 1
  • 1
NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
  • Yes, but your validateCurrentPage overload will not be called as virtual method from C++. Try to do something in overload(self) and click next on wizard page. From my tests it works only when you derive from QWizard and define overloaded method there. – Lukasz Jun 27 '14 at 17:34