From c936fc5982f5c11e0d5c411b366e5c7d6ac6bbd2 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 6 Mar 2024 20:12:40 +0100 Subject: [PATCH] Welcome: Determine maximum width for Core::Button text for all states Button states can have individual text tokens assigned. Depending on the used fonts and platform-specific renderer, any of these states may have the highest widts. Consider all of them and use the maximum. Change-Id: I51caccef9e34c1911c2773b8836dba722ad63c47 Reviewed-by: Alessandro Portale Reviewed-by: --- src/plugins/coreplugin/welcomepagehelper.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp index 87ee6a07c4b..49e15f1acac 100644 --- a/src/plugins/coreplugin/welcomepagehelper.cpp +++ b/src/plugins/coreplugin/welcomepagehelper.cpp @@ -147,11 +147,16 @@ Button::Button(const QString &text, Role role, QWidget *parent) QSize Button::minimumSizeHint() const { - const TextFormat &tf = buttonTF(m_role, WidgetStateHovered); - const QFontMetrics fm(tf.font()); - const QSize textS = fm.size(Qt::TextShowMnemonic, text()); + int maxTextWidth = 0; + for (WidgetState state : {WidgetStateDefault, WidgetStateChecked, WidgetStateHovered} ) { + const TextFormat &tf = buttonTF(m_role, state); + const QFontMetrics fm(tf.font()); + const QSize textS = fm.size(Qt::TextShowMnemonic, text()); + maxTextWidth = qMax(maxTextWidth, textS.width()); + } + const TextFormat &tf = buttonTF(m_role, WidgetStateDefault); const QMargins margins = contentsMargins(); - return {margins.left() + textS.width() + margins.right(), + return {margins.left() + maxTextWidth + margins.right(), margins.top() + tf.lineHeight() + margins.bottom()}; }