summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-11-17 21:21:57 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-11-20 23:19:19 +0100
commitb03557287fef291fc0a79ba2dc7c0f8bb3a0547b (patch)
tree8ee389e7fac45a868322a1faaa12ba7447f64146 /src/widgets/styles
parent778acfe122baf5a65c1001e78050f333106a840d (diff)
QPushButton: fix QPushButton with icon in rtl mode
In rtl mode the text was not aligned right so a gap between the text and the icon occurred. This was due to the fact that the textFlag given to qt_format_text() was modified based on the application wide rtl/ltr mode and so our Qt::RightToLeft was reverted to Qt::LeftToRight. Therefore only set the textFlag to Qt::AlignRight when the button layout direction does not match the global one. Pick-to: 6.6 Fixes: QTBUG-64373 Change-Id: I283a99de8f59bc3db53c4150f417ffef9ff68db7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index b4e414ce4e..3fca57a03f 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -1389,13 +1389,16 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
iconRect = visualRect(button->direction, textRect, iconRect);
- if (button->direction == Qt::RightToLeft) {
- tf |= Qt::AlignRight;
+ if (button->direction == Qt::RightToLeft)
textRect.setRight(iconRect.left() - iconSpacing / 2);
- } else {
- tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
+ else
textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing / 2);
- }
+
+ // qt_format_text reverses again when painter->layoutDirection is also RightToLeft
+ if (p->layoutDirection() == button->direction)
+ tf |= Qt::AlignLeft;
+ else
+ tf |= Qt::AlignRight;
if (button->state & (State_On | State_Sunken))
iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),