PyQt4 QWizard: How to disable the back button on a single page?

Question:

I would like to disable the “Back” button on a QWizard page.

My Class inherits from QWizard and from a generated file. It looks somehow like this:

from PyQt4 import QtGui

class WizardClass(QtGui.QWizard, file.Ui_Wizard):

    def __init__(self, model):
        # Call super constructors
        QtGui.QWizard.__init__(self)
        self.setupUi(self)
        self.model = model

Here http://doc.qt.digia.com/3.3/qwizard.html#backButton I found the method setBackEnabled().

With self.setBackEnabled(page1, False) I am not able to call this method. It says:

"AttributeError: 'WizardClass' object has no attribute 'setBackEnabled'"

Am I doing something wrong?

Or is this method not available in Python?

Asked By: jonie83

||

Answers:

An example that seems to work:

from PyQt4 import QtGui

class Wiz(QtGui.QWizard):

    def __init__(self):
        QtGui.QWizard.__init__(self)
        self.noback = []
        self.currentIdChanged.connect(self.disable_back)

    def disable_back(self, ind):
        if ind in self.noback:
            self.button(QtGui.QWizard.BackButton).setEnabled(False)

wiz = Wiz()
wiz.noback = [2]
wiz1 = QtGui.QWizardPage(wiz)
wiz2 = QtGui.QWizardPage(wiz)
wiz3 = QtGui.QWizardPage(wiz)

wiz.addPage(wiz1)
wiz.addPage(wiz2)
wiz.addPage(wiz3)

wiz.show()
Answered By: mdurant
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.