diff --git a/src/kstyle/kstyle.cpp b/src/kstyle/kstyle.cpp --- a/src/kstyle/kstyle.cpp +++ b/src/kstyle/kstyle.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -274,8 +275,10 @@ if (QDialogButtonBox *box = qobject_cast(w)) { QPushButton *button = box->button(QDialogButtonBox::Ok); - if (button && button->shortcut().isEmpty()) { - button->setShortcut(Qt::CTRL | Qt::Key_Return); + + if (button) { + auto shortcut = new QShortcut(Qt::CTRL | Qt::Key_Return, button); + QObject::connect(shortcut, &QShortcut::activated, button, &QPushButton::click); } } diff --git a/tests/kstyletest.cpp b/tests/kstyletest.cpp --- a/tests/kstyletest.cpp +++ b/tests/kstyletest.cpp @@ -45,12 +45,19 @@ dialog->setLayout(new QVBoxLayout); QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, dialog.data()); - QObject::connect(box, SIGNAL(accepted()), dialog.data(), SLOT(accept())); - QObject::connect(box, SIGNAL(rejected()), dialog.data(), SLOT(reject())); - dialog->layout()->addWidget(new QTextEdit(dialog.data())); + //Useful to change the text because setting the text triggers setShortcut + box->button(QDialogButtonBox::Ok)->setText(QLatin1String("Send")); + QObject::connect(box, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); + QObject::connect(box, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); + + auto usefulWidget = new QTextEdit(dialog.data()); + dialog->layout()->addWidget(usefulWidget); dialog->layout()->addWidget(box); + //Make sure we test ctrl+return acceptance with the focus on the button + usefulWidget->setFocus(); + dialog->resize(200, 200); dialog->exec(); }