Reputation: 45
I have QtInputDialog and I dont like it that, when i press enter it closes.
I would like to type value and confirm it by pressing enter on keyboard. After that line edit resets and i can type another value.
Upvotes: 0
Views: 279
Reputation: 40502
Dialog initialization:
void MainWindow::on_button1_clicked() {
dialog = new QInputDialog();
dialog->installEventFilter(this);
dialog->show();
}
Event filter:
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;
}
Note that the dialog still can be closed using mouse click on "OK".
Upvotes: 1