Reading the documentation here...<br><br><a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qvalidator.html" target="_blank">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qvalidator.html</a><br>
<br>... I see that the validate() function is listed twice.<br>
One returning (State, QString, int) and another returning just (State, int)<br>I would think this means I have the choice to return either 2-tuple or a 3-tuple.<br><br>Returning a 2-tuple seems to work fine but I get an error trying to return (State, QString, and int)<br>
<br>Is this a bug, or did I miss something or interpret the documentation wrong?<br><br>Code is below.<br><br>As a side note...<br>I have tried sending this twice before but it never got through to where I could read it in the archives.<br>
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.<br>
<br>Thanks,<br>~Eric<br><br><br><br>#!/usr/bin/env python<br><br>import sys<br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br>
<br>class EricsValidator(QValidator):<br> <br> def validate(self, text, position):<br> print 'validate (%s %s)' % (repr(text), repr(position))<br> return (QValidator.Intermediate, text, position)<br>
<br>class Form(QDialog):<br><br> def __init__(self, parent=None):<br> <br> super(Form, self).__init__(parent)<br> <br> self.lineedit = QLineEdit()<br> <br> self.validators = []<br>
layout = QGridLayout()<br> layout.addWidget(self.lineedit, 0, 0, 1, 2)<br><div id=":3d"> for i, (name, validator) in enumerate([<br> ("Q&IntValidator" , QIntValidator(self) ),<br>
("Q&DoubleValidator", QDoubleValidator(self)),<br>
("&Eric's Validator", EricsValidator(self) ),<br> ]):<br> label = QLabel(name)<br> button = QRadioButton()<br> label.setBuddy(button)<br> self.validators.append((validator, label, button))<br>
layout.addWidget(label , i + 1, 0)<br> layout.addWidget(button, i + 1, 1)<br> label.setBuddy(button)<br> <br> self.connect(button, SIGNAL("clicked()"), self.update)<br>
<br> self.validators[-1][2].setChecked(True)<br> <br> self.setLayout(layout)<br> <br> self.setWindowTitle("Validation Tester")<br> <br> self.update()<br>
<br>
def update(self):<br> <br> for validator, label, button in self.validators:<br> if button.isChecked():<br> print 'setting validator to', label.text()<br> self.lineedit.setValidator(validator)<br>
break<br><br><br>if __name__ == '__main__':<br> app = QApplication(sys.argv)<br> form = Form()<br> form.show()<br> app.exec_()</div>