aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2024-03-06 20:12:40 +0100
committerAlessandro Portale <alessandro.portale@qt.io>2024-03-07 12:00:04 +0000
commitc936fc5982f5c11e0d5c411b366e5c7d6ac6bbd2 (patch)
tree4094e74171f930d753990f245fe7c8b11f263b78
parent256105d75f892e318f65674c071843424145e7c7 (diff)
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 <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/coreplugin/welcomepagehelper.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/plugins/coreplugin/welcomepagehelper.cpp b/src/plugins/coreplugin/welcomepagehelper.cpp
index 87ee6a07c4..49e15f1aca 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()};
}