remove redundant check in QPushButton::sizeHint()

QPushButton::setAutoDefault() invalidates the cached size hint

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-14 12:57:23 +03:00
parent d87d2a4e09
commit a8068fc969
2 changed files with 6 additions and 5 deletions

View file

@ -330,7 +330,7 @@ bool QPushButton::autoDefault() const
{ {
Q_D(const QPushButton); Q_D(const QPushButton);
if(d->autoDefault == QPushButtonPrivate::Auto) if(d->autoDefault == QPushButtonPrivate::Auto)
return ( d->dialogParent() != 0 ); return (d->dialogParent() != 0);
return bool(d->autoDefault); return bool(d->autoDefault);
} }
@ -359,9 +359,9 @@ bool QPushButton::isDefault() const
QSize QPushButton::sizeHint() const QSize QPushButton::sizeHint() const
{ {
Q_D(const QPushButton); Q_D(const QPushButton);
if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault()) if (d->sizeHint.isValid()) {
return d->sizeHint; return d->sizeHint;
d->lastAutoDefault = autoDefault(); }
ensurePolished(); ensurePolished();
int w = 0, h = 0; int w = 0, h = 0;

View file

@ -48,7 +48,9 @@ public:
QPushButtonPrivate() QPushButtonPrivate()
: QAbstractButtonPrivate(QSizePolicy::PushButton), autoDefault(Auto), : QAbstractButtonPrivate(QSizePolicy::PushButton), autoDefault(Auto),
defaultButton(false), flat(false), menuOpen(false), lastAutoDefault(false) {} defaultButton(false), flat(false), menuOpen(false)
{
}
inline void init() { resetLayoutItemMargins(); } inline void init() { resetLayoutItemMargins(); }
static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); }
@ -64,7 +66,6 @@ public:
bool defaultButton; bool defaultButton;
bool flat; bool flat;
bool menuOpen; bool menuOpen;
mutable bool lastAutoDefault;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE