[PyQt] Issue with QValidator

Thomas Daniel tomek.daniel at gmail.com
Thu Dec 22 17:18:16 GMT 2016


Here is the simple test script:

#!/usr/bin/env python3

from PyQt5.QtWidgets import *
from PyQt5.QtGui     import *
from PyQt5.QtCore    import *

import sys

class Validator(QValidator):
    def __init__(self, parent = None):
        super().__init__(parent)
    def validate(self, name, pos):
        return QValidator.Acceptable

class Widget(QDialog):
    def __init__(self, parent = None):
        super().__init__(parent)
        line_edit = QLineEdit(self)
        line_edit.setValidator(Validator())

app     = QApplication(sys.argv)
widget  = Widget()
widget.show()
app.exec_()


Running the script results in
TypeError: invalid result from Validator.validate()

Testing with PyQt5.7 on ubuntu 16.04, installed with apt-get install
python3-pyqt5.

I can't figure out what I am doing wrong!

Thanks
Thomas


More information about the PyQt mailing list