title: User Input Validation in PyQt5 and Python
body: <p>This is a two part question about input validation with one specific and another more general component.</p>
  
  <p><strong>The specific:</strong></p>
  
  <p>While researching the topic, I found <a href="https://stackoverflow.com/questions/32194431/pyqt4-user-input-validation-qlineedit" title="THIS">THIS</a> on Regular Expressions.
  I realize that the code in this post is using PyQt4. However I wanted to get this working with PyQt5, since I had already started my project with it. (Obviously blindly - I can only find C++ documentation for it)</p>
  
  <p>This is what I tried:</p>
  
  <pre><code># somewhere above:     
  self.le_input = QtWidgets.QLineEdit()
  
  # at some point validate_input gets called:
  # more on that in the second part of this question
  
  def validate_input(self):
      reg_ex = QtCore.QRegExp(""[0-9]+.?[0-9]{,2}"")
      input_validator = QtGui.QRegExpValidator(reg_ex, self.le_input.text())
      self.le_input.setValidator(input_validator)
  </code></pre>
  
  <p>When I run the code I get the following Error:</p>
  
  <blockquote>
    <p>QRegExpValidator(parent: QObject = None): argument 1 has unexpected type 'QRegExp'
    QRegExpValidator(QRegExp, parent: QObject = None): argument 2 has unexpected type 'str'</p>
  </blockquote>
  
  <p>Aren't these exactly the required arguments?
  Does anyone know how to get this working? </p>
  
  <hr>
  
  <p><strong>The general:</strong></p>
  
  <p>What is an effective way to implement live validation with PyQt in Python?</p>
  
  <p>At the moment I would use:</p>
  
  <pre><code>self.le_input.textChanged.connect(self.validate_input)
  </code></pre>
  
  <p>This does work, but as soon as I try to connect two QtLineEdits, that affect each other, to the same slot, things stop working because "textChanged" gets called by both of them at the same time.</p>
  
  <p>Use case: Two input fields:  <code>Amount before TAX</code> and <code>Amount after TAX</code> - and whichever you enter automatically fills the other one while typing.</p>
  
  <p>First validation, then calculation, then output to the other field.</p>
  
  <p><strong>Many thanks in advance! Any help is highly appreciated!</strong></p>