title: PyQt: QValidator Function Definition
body: <p>I am currently using a quite brutal approach in getting of what QValidator would deliver with ease. Locating a simple info on this widget is quite difficult. A code below copied/pasted (after some minor editing) from another post. It creates a dialog with single lineEdit connected to ValidStringLength QValidator which enforces a string size to be 0 &lt; length &lt; 5. I would like to understand where should be a string-cleaning "executable" function placed: inside a fixup() method? Please explain the logic behind QValidator().</p>
  
  <hr>
  
  <pre><code>   from PyQt4 import QtCore, QtGui
      class ValidStringLength(QtGui.QValidator):
          def __init__(self, min, max, parent):
              QtGui.QValidator.__init__(self, parent)
  
              self.min = min
              self.max = max
  
          def validate(self, s, pos):
              print 'validate(): ', type(s), type(pos), s, pos
  
              if self.max &gt; -1 and len(s) &gt; self.max:
                  return (QtGui.QValidator.Invalid, pos)
  
              if self.min &gt; -1 and len(s) &lt; self.min:
                  return (QtGui.QValidator.Intermediate, pos)
  
              return (QtGui.QValidator.Acceptable, pos)
  
          def fixup(self, s):
              pass
  
  
      class Window(QtGui.QWidget):
          def __init__(self):
              QtGui.QWidget.__init__(self)
  
              self.editLine = QtGui.QLineEdit(self)
              self.validator = ValidStringLength(0,5,self)
  
              self.editLine.setValidator(self.validator)
  
              layout = QtGui.QVBoxLayout(self)
              layout.addWidget(self.editLine)
  
      if __name__ == '__main__':
  
          import sys
          app = QtGui.QApplication(sys.argv)
          window = Window()
          window.setGeometry(500, 300, 500, 100)
          window.show()
          sys.exit(app.exec_())
  </code></pre>