Revert "Revert "kstyle: Limit what kinds of QPushButtons can use autoDefault""

This reverts commit 916cc11f35.

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.
wilder-5.24
Noah Davis 4 years ago
parent 916cc11f35
commit 4195dd40ff
  1. 19
      kstyle/breezestyle.cpp

@ -49,6 +49,7 @@
#include <QTreeView>
#include <QWidgetAction>
#include <QMdiArea>
#include <QDialogButtonBox>
#include <QGraphicsItem>
#include <QGraphicsProxyWidget>
@ -421,6 +422,24 @@ namespace Breeze
widget->setAttribute(Qt::WA_StyledBackground);
} else if ( auto spbx = qobject_cast<QAbstractSpinBox*> (widget) ) {
spbx->setAlignment(Qt::AlignCenter);
} else if (auto pushButton = qobject_cast<QPushButton*>(widget)) {
QDialog *dialog = nullptr;
auto p = pushButton->parentWidget();
while (p && !p->isWindow()) {
p = p->parentWidget();
if (auto d = qobject_cast<QDialog*>(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<QDialogButtonBox*>(pushButton->parent());
pushButton->setAutoDefault(autoDefaultNoDialog || (autoDefaultInDialog && dialogButtonBox));
}

Loading…
Cancel
Save