totymedli
totymedli

Reputation: 31098

How to set QLineEdit default text to one space?

I entered one space as a QLineEdit's text in the Qt Creator GUI Designer. I can see that the space is there in the designer wiew, but if I compile and run it, the space disapears. I want this space to be a QLineEdit's default text, how can set it, or tell Qt to do not delete that one space?

Upvotes: 4

Views: 29204

Answers (2)

user362638
user362638

Reputation:

My guess is that space disappears because UIs are stored as XML and nodes consisting only of whitespace are strippd (see this question).

But you can set the space to the QLineEdit in the window's constructor:

ui->lineEdit->setText(" ");

Upvotes: 7

jdi
jdi

Reputation: 92567

If what you want is to have a default text when the widget is empty, use the setPlaceholderText(QString)

If you want to just set a initial value, then do it in the constructor of your app/widget/class with setText(QString)

Upvotes: 8

Related Questions