gpt4 book ai didi

c++ - Qt输入对话框——输入值不关闭

转载 作者:行者123 更新时间:2023-11-28 07:17:39 26 4
gpt4 key购买 nike

我有 QtInputDialog 但我不喜欢它,当我按下回车键时它会关闭。

我想输入值并按键盘上的回车键确认。在该行编辑重置后,我可以输入另一个值。

最佳答案

对话框初始化:

void MainWindow::on_button1_clicked() {
dialog = new QInputDialog();
dialog->installEventFilter(this);
dialog->show();
}

事件过滤器:

bool MainWindow::eventFilter(QObject *o, QEvent *e) {
if (e->type() == QEvent::KeyPress) {
if (static_cast<QKeyEvent*>(e)->matches(QKeySequence::InsertParagraphSeparator)) {
qDebug() << dialog->textValue(); //use this value as you wish
dialog->setTextValue(QString());
return true; //block this event
}
}
return false;
}

请注意,仍然可以使用鼠标单击“确定”关闭对话框。

关于c++ - Qt输入对话框——输入值不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19985626/

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