On Monday 24 February 2003 8:33 pm, Jonathan Gardner wrote:
> I am trying to implement my own QValidator so that I can do cool things
> like enter money, phone numbers, etc...
>
> Anyway, I would like to be able to modify the QString passed into fixup().
> However, the code below (obviously) doesn't work.
>
> # Begin code
> import sys
> from qt import *
>
> class validator(QValidator):
>
> def __init__(self, parent=None, name=None):
> QValidator.__init__(self, parent, name)
>
> def validate(self, input, pos):
> return (QValidator.Intermediate, pos)
>
> def fixup(self, input):
> # How to do an in-place modification of input?
> input = QString("no!")
>
> class test_validator(QWidget):
>
> def __init__(self, parent=None, name=None, fl=0):
> QWidget.__init__(self, parent, name, fl)
>
> lo = QVBoxLayout(self, 11, 6)
>
> self.le = QLineEdit(self)
> self.le.setValidator(validator(self.le))
>
> lo.addWidget(self.le)
>
> if __name__ == "__main__":
> app = QApplication(sys.argv)
> args = app.argv()
> QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()"))
> w = test_validator()
> app.setMainWidget(w)
> w.show()
> app.exec_loop()
> # End code
>
> This method above doesn't work. I need a way to modify 'input' so that
> fixup can actually do something.
>
> Any ideas?
>
> Or should I be returning the the value like it does for other functions
> that accept a C++ '&' parameter? (And since PyQt doesn't handle this... is
> it a bug?)
Your code is replacing the string with a new one rather than trying to modify
the one passed in. For example the following will convert the input to upper
case...
def fixup(self, input):
input.replace(0,100,input.upper())
I admit that this isn't particularly intuitive - one of those things that I
might do a different way if I was starting again.
Phil
___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde