[PyQt] QValidator.validate() returns TypeError: invalid result type

Eric Frederich eric.frederich at gmail.com
Thu Aug 5 02:22:47 BST 2010

Reading the documentation here...


... I see that the validate() function is listed twice.
One returning (State, QString, int) and another returning just (State, int)
I would think this means I have the choice to return either 2-tuple or a

Returning a 2-tuple seems to work fine but I get an error trying to return
(State, QString, and int)

Is this a bug, or did I miss something or interpret the documentation wrong?

Code is below.

As a side note...
I have tried sending this twice before but it never got through to where I
could read it in the archives.
Perhaps I need to be subscribed to the list to post to it??? If so it
doesn't say that on the mailing list web page.


#!/usr/bin/env python

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import  *

class EricsValidator(QValidator):

    def validate(self, text, position):
        print 'validate (%s %s)' % (repr(text), repr(position))
        return (QValidator.Intermediate, text, position)

class Form(QDialog):

    def __init__(self, parent=None):

        super(Form, self).__init__(parent)

        self.lineedit = QLineEdit()

        self.validators = []
        layout = QGridLayout()
        layout.addWidget(self.lineedit, 0, 0, 1, 2)
        for i, (name, validator) in enumerate([
            ("Q&IntValidator"   , QIntValidator(self)   ),
            ("Q&DoubleValidator", QDoubleValidator(self)),
            ("&Eric's Validator", EricsValidator(self)  ),
            label  = QLabel(name)
            button = QRadioButton()
            self.validators.append((validator, label, button))
            layout.addWidget(label , i + 1, 0)
            layout.addWidget(button, i + 1, 1)

            self.connect(button, SIGNAL("clicked()"), self.update)



        self.setWindowTitle("Validation Tester")


    def update(self):

        for validator, label, button in self.validators:
            if button.isChecked():
                print 'setting validator to', label.text()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = Form()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100804/03d19612/attachment.html>

More information about the PyQt mailing list