Reputation: 596
I am trying to fill the default text into LineEdit field of QInputDialog (like filling the old value to rename, for example). Here is the code:
bool dialogResult;
QInputDialog *renameDialog = new QInputDialog();
renameDialog->setTextValue("Test"); // has no effect
QString result = renameDialog->getText(0, "Rename Label", "New name:", QLineEdit::Normal,
"", &dialogResult);
if(result.length() > 0 && dialogResult) setText(result);
How can I set a value to InputDialog
to make it filled by default?
Upvotes: 3
Views: 9265
Reputation: 36630
You need to pass the default text as fifth parameter:
QString result = renameDialog->getText(0, "Rename Label", "New name:", QLineEdit::Normal,
"DEFAULT TEXT", &dialogResult);
See also QInputDialog::getText():
... text is the default text which is placed in the line edit ...
Upvotes: 8