From 4195dd40ff57cf08bb7bfe49e1b9412bd0dcf228 Mon Sep 17 00:00:00 2001 From: Noah Davis Date: Fri, 8 Oct 2021 16:52:48 -0400 Subject: [PATCH] Revert "Revert "kstyle: Limit what kinds of QPushButtons can use autoDefault"" This reverts commit 916cc11f35dbb53624cf1713faf3ac785f073462. I'm reverting the reversion on master because the reason for reverting the original commit seems to have been based purely on an assumption about what the patch did rather than testing anything. --- kstyle/breezestyle.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 7fb3b87b..951713a0 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -421,6 +422,24 @@ namespace Breeze widget->setAttribute(Qt::WA_StyledBackground); } else if ( auto spbx = qobject_cast (widget) ) { spbx->setAlignment(Qt::AlignCenter); + } else if (auto pushButton = qobject_cast(widget)) { + QDialog *dialog = nullptr; + auto p = pushButton->parentWidget(); + while (p && !p->isWindow()) { + p = p->parentWidget(); + if (auto d = qobject_cast(p)) { + dialog = d; + } + } + // Internally, QPushButton::autoDefault can be explicitly on, + // explicitly off, or automatic (enabled if in a QDialog). + // If autoDefault is explicitly on and not in a dialog, + // or on/automatic in a dialog and has a QDialogButtonBox parent, + // explicitly enable autoDefault, else explicitly disable autoDefault. + bool autoDefaultNoDialog = pushButton->autoDefault() && !dialog; + bool autoDefaultInDialog = pushButton->autoDefault() && dialog; + auto dialogButtonBox = qobject_cast(pushButton->parent()); + pushButton->setAutoDefault(autoDefaultNoDialog || (autoDefaultInDialog && dialogButtonBox)); }