Revert "QPushButton: fix support of style sheet rule for text alignment"

This reverts commit 6269438af9, and adds a test.

This change introduced QTBUG-91735, without fixing QTBUG-86857 correctly. The
code already interprets the textAlignment values from the rule, also if no
icon is set. Adding the same, or some default textAlignment to the text flags
if there is no icon doesn't work.

Fixes: QTBUG-91735
Task-number: QTBUG-86857
Pick-to: 6.1 6.0 5.15
Change-Id: Iee07e63a40e72909275f32e1caa28b33a595f879
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-03-11 14:01:28 +01:00
parent dbdde8d023
commit 674747bac1
2 changed files with 20 additions and 4 deletions

View File

@ -3569,8 +3569,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
const uint horizontalAlignMask = Qt::AlignHCenter | Qt::AlignLeft | Qt::AlignRight; const uint horizontalAlignMask = Qt::AlignHCenter | Qt::AlignLeft | Qt::AlignRight;
const uint verticalAlignMask = Qt::AlignVCenter | Qt::AlignTop | Qt::AlignBottom; const uint verticalAlignMask = Qt::AlignVCenter | Qt::AlignTop | Qt::AlignBottom;
const Qt::Alignment textAlignment = rule.position()->textAlignment; if (rule.hasPosition() && rule.position()->textAlignment != 0) {
if (rule.hasPosition() && textAlignment != 0) { Qt::Alignment textAlignment = rule.position()->textAlignment;
tf |= (textAlignment & verticalAlignMask) ? (textAlignment & verticalAlignMask) : Qt::AlignVCenter; tf |= (textAlignment & verticalAlignMask) ? (textAlignment & verticalAlignMask) : Qt::AlignVCenter;
tf |= (textAlignment & horizontalAlignMask) ? (textAlignment & horizontalAlignMask) : Qt::AlignHCenter; tf |= (textAlignment & horizontalAlignMask) ? (textAlignment & horizontalAlignMask) : Qt::AlignHCenter;
if (!styleHint(SH_UnderlineShortcut, button, w)) if (!styleHint(SH_UnderlineShortcut, button, w))
@ -3629,8 +3629,6 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
iconRect.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, w), iconRect.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, w),
pixelMetric(PM_ButtonShiftVertical, opt, w)); pixelMetric(PM_ButtonShiftVertical, opt, w));
p->drawPixmap(iconRect, pixmap); p->drawPixmap(iconRect, pixmap);
}else {
tf |= textAlignment;
} }
if (button->state & (State_On | State_Sunken)) if (button->state & (State_On | State_Sunken))

View File

@ -73,6 +73,7 @@ private slots:
#endif #endif
void emitReleasedAfterChange(); void emitReleasedAfterChange();
void hitButton(); void hitButton();
void iconOnlyStyleSheet();
protected slots: protected slots:
void resetCounters(); void resetCounters();
@ -734,5 +735,22 @@ void tst_QPushButton::hitButton()
QVERIFY(!button2->hitButton(QPoint(2, 2))); QVERIFY(!button2->hitButton(QPoint(2, 2)));
} }
/*
Test that a style sheet with only icon doesn't crash.
QTBUG-91735
*/
void tst_QPushButton::iconOnlyStyleSheet()
{
QIcon icon(":/qt-project.org/styles/commonstyle/images/dvd-32.png");
QVERIFY(!icon.isNull());
QPushButton pb;
pb.setStyleSheet("QPushButton {"
"icon: url(:/qt-project.org/styles/commonstyle/images/dvd-32.png);"
"border: red;"
"}");
pb.show();
QVERIFY(QTest::qWaitForWindowExposed(&pb));
}
QTEST_MAIN(tst_QPushButton) QTEST_MAIN(tst_QPushButton)
#include "tst_qpushbutton.moc" #include "tst_qpushbutton.moc"