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.

Fixes: QTBUG-64373
Change-Id: I283a99de8f59bc3db53c4150f417ffef9ff68db7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit b03557287fef291fc0a79ba2dc7c0f8bb3a0547b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2023-11-17 21:21:57 +01:00 committed by Qt Cherry-pick Bot
parent 5be3bf0598
commit 9c84620d4b

View File

@ -1396,13 +1396,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),