CecchinoSMI
CecchinoSMI

Reputation: 169

A suggest to solve QLineEdit property

I'm working with Qt5...and I'm tryng to set a default value in QLineEdit in case of I wrote nothing in the linetext area. Is possible to do that?

Upvotes: 0

Views: 168

Answers (2)

hyde
hyde

Reputation: 62797

If you want user to have empty field when they start editing

First use placeHolderText property of QLineEdit to set the default value to display.

Then connect editingFinished (or possibly some other, check them out) signal to your own slot, where you check if text is empty (and then use the placeHolderText value) or if user entered something.

If you want to leave default text for user to edit

Instead of using placeHolderText, simply set contents of the QLineEdit to desired default value, when you create it. Then in the slot for editingFinished, if user made field empty, restore the text to default.

Upvotes: 1

kajojeq
kajojeq

Reputation: 904

You can do this for example by connecting

 void QLineEdit::editingFinished () [signal]

and check in the slot actual text from QLineEdit and if necessary set yours.

Upvotes: 1

Related Questions