From 00a04076ce5041637fbcad0fb76e3ebc9269eee6 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sat, 28 Mar 2026 11:53:20 -0400 Subject: [PATCH] fix: improve button text rendering when size is constrained --- ...pushbutton-text-not-drawn-when-small.patch | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/patches/160-fix-pushbutton-text-not-drawn-when-small.patch b/patches/160-fix-pushbutton-text-not-drawn-when-small.patch index 182dbf7..1ccbe67 100644 --- a/patches/160-fix-pushbutton-text-not-drawn-when-small.patch +++ b/patches/160-fix-pushbutton-text-not-drawn-when-small.patch @@ -1,5 +1,5 @@ diff --git a/lib/src/style/QlementineStyle.cpp b/lib/src/style/QlementineStyle.cpp -index 07151b9..d80a1e8 100644 +index 07151b9..3216716 100644 --- a/lib/src/style/QlementineStyle.cpp +++ b/lib/src/style/QlementineStyle.cpp @@ -1107,8 +1107,7 @@ void QlementineStyle::drawControl(ControlElement ce, const QStyleOption* opt, QP @@ -21,12 +21,27 @@ index 07151b9..d80a1e8 100644 const auto textRect = QRect{ availableX, contentRect.y(), elidedTextW, contentRect.height() }; int textFlags = Qt::AlignVCenter | Qt::AlignBaseline | Qt::TextSingleLine | Qt::TextHideMnemonic; if (iconW == 0) { -@@ -2381,6 +2380,9 @@ QRect QlementineStyle::subElementRect(SubElement se, const QStyleOption* opt, co +@@ -2380,7 +2379,23 @@ QRect QlementineStyle::subElementRect(SubElement se, const QStyleOption* opt, co + const auto hasText = !optButton->text.isEmpty(); const auto hasMenu = optButton->features.testFlag(QStyleOptionButton::HasMenu); const auto padding = pixelMetric(PM_ButtonMargin); - const auto [paddingLeft, paddingRight] = getHPaddings(hasIcon, hasText, hasMenu, padding); -+ if (paddingLeft + paddingRight >= opt->rect.width()) { +- const auto [paddingLeft, paddingRight] = getHPaddings(hasIcon, hasText, hasMenu, padding); ++ auto [paddingLeft, paddingRight] = getHPaddings(hasIcon, hasText, hasMenu, padding); ++ const auto totalPadding = paddingLeft + paddingRight; ++ if (totalPadding >= opt->rect.width()) { + return opt->rect; ++ } ++ // When the button is squeezed below its ideal size, reduce padding ++ // proportionally by the deficit so content space is preserved first. ++ if (hasText && totalPadding > 0) { ++ const auto textW = qlementine::textWidth(optButton->fontMetrics, optButton->text); ++ const auto idealWidth = textW + totalPadding; ++ if (opt->rect.width() < idealWidth) { ++ const auto deficit = idealWidth - opt->rect.width(); ++ const auto reduction = std::min(deficit, totalPadding); ++ paddingLeft -= paddingLeft * reduction / totalPadding; ++ paddingRight -= paddingRight * reduction / totalPadding; ++ } + } return opt->rect.marginsRemoved({ paddingLeft, 0, paddingRight, 0 }); }