Skip to content

Commit

Permalink
More layout-friendly PixmapButton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelgregorius committed Oct 9, 2024
1 parent 1388462 commit ea980bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/PixmapButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions src/gui/widgets/PixmapButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ea980bf

Please sign in to comment.