我正在尝试将默认文本填充到QInputDialog的LineEdit字段中(例如,填充旧值以重命名)。这是代码:
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);
如何将值设置为InputDialog
以使其默认填充?
答案 0 :(得分:4)
您需要将默认文本作为第五个参数传递:
QString result = renameDialog->getText(0, "Rename Label", "New name:", QLineEdit::Normal,
"DEFAULT TEXT", &dialogResult);
... text是放置在行编辑中的默认文本...