How can I make QLineEdit paint a different text than the one assigned?



  • Hello,

    I have a QLineEdit with a numerical validator ranging from -100 to 100. But I need the symbol "-" to be represented with the character "M".

    I have already tried the following:
       - Overwrite the text () method and do the replacement here. (It does not work)
       - Override the displayText () method and put the setEchoMode (). (It does not work)
       - Override the paintEvent () method. (Works, but does not look the same as any other QLineEdit)

    Is there anything else I can do to get this effect?

    Thanks all in advance.



  • Hi,
    in case of a QSpinBox I did something similar by overriding the QValidator::State validate(QString &input, int &pos) const function (changing numbers 1,2,... to characters A,B,...). So either you could use a QSpinBox instead of the QLineEdit or maybe it's possible to do the same thing using the fixup method of a QValidator that you add to the QLineEdit.
    -Michael.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.