PyQt - Using Multiple Validators for Item Delegate

2019-08-21 19:26发布

问题:

Based on a previous question, I am using the QDoubleValidator class every time a cell is changed in a QTableView. Is there any way to use a combination of classes when checking the input?

For example I would like to have it that '3m' could be a valid input, where I can parse the certain value 'm' and convert the float into another float, eg 3000000. I would also like to be able to check for some other types of inputs.

This is my current Item Delegate;

class FloatDelegate(QItemDelegate):
    def __init__(self, parent=None):
        QItemDelegate.__init__(self, parent=parent)

    def createEditor(self, parent, option, index):
        editor = QLineEdit(parent)
        editor.setValidator(QDoubleValidator())
        return editor

I was unable to find something regarding the setValidator and how to handle a combination of Validator classes and how to process their inputs.

Thanks!