Important: Please read the Qt Code of Conduct -

How to apply QIntValidator for QTextEdit

  • Hi All,

    Is there any way to apply integer and real validator to QTextEdit widget ?
    I have tried but i am not able to apply the QIntValidator to QTextEdit. For that i have to use QLineEdit.

    Is there anyway i can apply integer and real validator in QTextEdit ?


  • What's wrong or unclear with the "example of use" in the [[Doc:QIntValidator]] docs?

  • This example validator is applied on QLineEdit that is applicable. But I am not able to apply validator on QTextEdit.

  • I could only solve in this way:
    QString QTextEdit::toPlainText();
    And after this I could use the validator.

  • Ah, sorry, I misread and confused TEXT edit with LINE edit.

    I don't get the use case, though. The text edit widget is designed for multi-line, probably rich, text, whereas an integer or real number is only one line and would best fit into a line edit...

  • I guess your problem is that QTextedit does not have a setValidator method.
    Why that is the case? Volker has given the answer. Multi-line may make it time consuming.

Log in to reply