2

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?

4

1 回答 1

6

您需要将默认文本作为第五个参数传递:

QString result = renameDialog->getText(0, "Rename Label", "New name:", QLineEdit::Normal,
                                       "DEFAULT TEXT", &dialogResult);

另见QInputDialog::getText()

... text 是放置在行编辑中的默认文本...

于 2013-07-30T08:14:48.863 回答