code: def isChar(ev):
      
      text = ev.text()
      if len(text) != 1:
          return False
  
      if ev.modifiers() not in (Qt.ShiftModifier, Qt.KeypadModifier, Qt.NoModifier):
          return False
  
      asciiCode = ord(text)
      if asciiCode <= 31 or asciiCode == 0x7f:  # control characters
          return False
  
      if text == ' ' and ev.modifiers() == Qt.ShiftModifier:
          return False  # Shift+Space is a shortcut, not a text
  
      return True
docs: Check if an event may be a typed character