gpt4 book ai didi

qt - 如何将默认文本填充到 QInputDialog

转载 作者:行者123 更新时间:2023-12-02 15:35:41 25 4
gpt4 key购买 nike

我正在尝试将默认文本填充到 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 设置一个值以使其默认填充?

最佳答案

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

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

另见 QInputDialog::getText() :

... text is the default text which is placed in the line edit ...

关于qt - 如何将默认文本填充到 QInputDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17941405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com