From ea980bf63818f7d1c29335fd5e87ef8624658d90 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Wed, 9 Oct 2024 12:54:31 +0200 Subject: [PATCH] More layout-friendly PixmapButton Make the `PixmapButton` more friendly for layouts by implementing `minimumSizeHint`. It returns a size that accommodate to show the active and the inactive pixmap. Also make `sizeHint` return the minimum size hint. The previous implementation would have made layouts jump when the pixmap is toggled with pixmaps of different sizes. --- include/PixmapButton.h | 1 + src/gui/widgets/PixmapButton.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/PixmapButton.h b/include/PixmapButton.h index 734bd11ae5c..a0b4141deba 100644 --- a/include/PixmapButton.h +++ b/include/PixmapButton.h @@ -45,6 +45,7 @@ class LMMS_EXPORT PixmapButton : public AutomatableButton void setInactiveGraphic( const QPixmap & _pm, bool _update = true ); QSize sizeHint() const override; + QSize minimumSizeHint() const override; signals: void doubleClicked(); diff --git a/src/gui/widgets/PixmapButton.cpp b/src/gui/widgets/PixmapButton.cpp index 069acad567c..5f2e01b3d24 100644 --- a/src/gui/widgets/PixmapButton.cpp +++ b/src/gui/widgets/PixmapButton.cpp @@ -124,16 +124,13 @@ void PixmapButton::setInactiveGraphic( const QPixmap & _pm, bool _update ) QSize PixmapButton::sizeHint() const { - if (isActive()) - { - return m_activePixmap.size(); - } - else - { - return m_inactivePixmap.size(); - } + return minimumSizeHint(); } +QSize PixmapButton::minimumSizeHint() const +{ + return m_activePixmap.size().expandedTo(m_inactivePixmap.size()); +} bool PixmapButton::isActive() const {