Reputation: 169
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
Reputation: 62797
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.
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
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