Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions patches/160-fix-pushbutton-text-not-drawn-when-small.patch
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 });
}
Expand Down
Loading