hydrogen-music / hydrogen

The advanced drum machine for Linux, macOS, and Windows
http://www.hydrogen-music.org
GNU General Public License v2.0
1.04k stars 173 forks source link

Button: fix adaptive font size (#1908) #1914

Closed theGreatWhiteShark closed 9 months ago

theGreatWhiteShark commented 9 months ago

Whenever the width of a text exceeds the width of the Button itself, the font size will be stepwise decreased till the text fits the button. This stepwise shrinking was done by assigning the font in each step and checking the resulting proportions.

Setting the font of a widget more than once, however, seems to mark it dirty and triggers rerendering. Since Button::updateFont() is called as part of Button::paintEvent() we will get ourselves trapped in an infinite loop.

Surprisingly, this was not triggered unless one uses one of the more outdated translations. And even more surprisingly this seems to not result in any bad behavior other than Qt being unable to open the native File browser on Linux (in a native build. AppImages were not affected).

The same fix was applied to ClickableLabel to assure we won't get into trouble there either.

Fixes https://github.com/hydrogen-music/hydrogen/issues/1908