From d945ac1cbef225369216a34d1b9d99a576848a06 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Mon, 8 Jan 2024 15:44:58 +0100 Subject: [PATCH] Fix scaling of PixmapButton in layouts (#7053) --- include/PixmapButton.h | 2 ++ src/gui/widgets/PixmapButton.cpp | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/PixmapButton.h b/include/PixmapButton.h index e8f546dc0..734bd11ae 100644 --- a/include/PixmapButton.h +++ b/include/PixmapButton.h @@ -56,6 +56,8 @@ protected: void mouseReleaseEvent( QMouseEvent * _me ) override; void mouseDoubleClickEvent( QMouseEvent * _me ) override; +private: + bool isActive() const; private: QPixmap m_activePixmap; diff --git a/src/gui/widgets/PixmapButton.cpp b/src/gui/widgets/PixmapButton.cpp index 13c09c52e..069acad56 100644 --- a/src/gui/widgets/PixmapButton.cpp +++ b/src/gui/widgets/PixmapButton.cpp @@ -50,20 +50,15 @@ PixmapButton::PixmapButton( QWidget * _parent, const QString & _name ) : -void PixmapButton::paintEvent( QPaintEvent * ) +void PixmapButton::paintEvent(QPaintEvent*) { - QPainter p( this ); + QPainter p(this); - if( ( model() != nullptr && model()->value() ) || m_pressed ) + QPixmap* pixmapToDraw = isActive() ? &m_activePixmap : &m_inactivePixmap; + + if (!pixmapToDraw->isNull()) { - if( !m_activePixmap.isNull() ) - { - p.drawPixmap( 0, 0, m_activePixmap ); - } - } - else if( !m_inactivePixmap.isNull() ) - { - p.drawPixmap( 0, 0, m_inactivePixmap ); + p.drawPixmap(0, 0, *pixmapToDraw); } } @@ -129,15 +124,20 @@ void PixmapButton::setInactiveGraphic( const QPixmap & _pm, bool _update ) QSize PixmapButton::sizeHint() const { - if( ( model() != nullptr && model()->value() ) || m_pressed ) + if (isActive()) { - return m_activePixmap.size() / devicePixelRatio(); + return m_activePixmap.size(); } else { - return m_inactivePixmap.size() / devicePixelRatio(); + return m_inactivePixmap.size(); } } +bool PixmapButton::isActive() const +{ + return (model() != nullptr && model()->value()) || m_pressed; +} + } // namespace lmms::gui