[PyKDE] Subclassing QValidator

Phil Thompson phil at river-bank.demon.co.uk
Wed Feb 6 10:50:58 GMT 2002


Seems to work fine with the current CVS. Try upgrading to PyQt 3.0.

Phil

"John J. Lee" wrote:
> 
> #!/usr/bin/env python
> 
> """With PyQt 2.4, I get infinite recursion on typing a character."""
> 
> import sys
> from qt import *
> 
> class FloatValidator(QDoubleValidator):
>     def fixup(self, input):
>         QDoubleValidator.fixup(self, input)
>         if input.length() == 0:
>             input.insert(0, "None")
> 
>     def validate(self, input, posn):
>         state, posn = QDoubleValidator.validate(self, input, posn)
>         if state != QValidator.Invalid:
>             return state, posn
>         if input == "None":
>             return QValidator.Acceptable, posn
>         elif "None".find(str(input)) == 0:
>             return QValidator.Intermediate, posn
> ##         else:
> ##             return QValidator.Invalid, posn
> 
> class FloatLineEdit(QLineEdit):
>     """Floating-point LineEdit, accepts empty input as 'None'."""
>     def __init__(self, *args):
>         QLineEdit.__init__(self, *args)
> #        self.setValidator(QDoubleValidator(self))
>         self.setValidator(FloatValidator(self))
> 
>     def sizeHint(self):
>         sz = QLineEdit.sizeHint(self)
>         return QSize(sz.width()/2, sz.height())
> 
> a = QApplication(sys.argv)
> mw = FloatLineEdit(None)
> #mw = QLineEdit(None)
> mw.show()
> a.connect(a, SIGNAL("lastWindowClosed()"), a, SLOT("quit()"))
> a.exec_loop()
> 
> # Also, QMessageBox.about doesn't seem look for icon method in parent
> # (sorry, no example code), contrary to the Qt docs.
> 
> # John
> 
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.gmd.de
> http://mats.gmd.de/mailman/listinfo/pykde




More information about the PyQt mailing list