summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp6
-rw-r--r--tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp18
2 files changed, 20 insertions, 4 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index e7662ba5c6..402f664252 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -3569,8 +3569,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
const uint horizontalAlignMask = Qt::AlignHCenter | Qt::AlignLeft | Qt::AlignRight;
const uint verticalAlignMask = Qt::AlignVCenter | Qt::AlignTop | Qt::AlignBottom;
- const Qt::Alignment textAlignment = rule.position()->textAlignment;
- if (rule.hasPosition() && textAlignment != 0) {
+ if (rule.hasPosition() && rule.position()->textAlignment != 0) {
+ Qt::Alignment textAlignment = rule.position()->textAlignment;
tf |= (textAlignment & verticalAlignMask) ? (textAlignment & verticalAlignMask) : Qt::AlignVCenter;
tf |= (textAlignment & horizontalAlignMask) ? (textAlignment & horizontalAlignMask) : Qt::AlignHCenter;
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),
pixelMetric(PM_ButtonShiftVertical, opt, w));
p->drawPixmap(iconRect, pixmap);
- }else {
- tf |= textAlignment;
}
if (button->state & (State_On | State_Sunken))
diff --git a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
index 5b80ec4e2f..e565645fa8 100644
--- a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
+++ b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
@@ -73,6 +73,7 @@ private slots:
#endif
void emitReleasedAfterChange();
void hitButton();
+ void iconOnlyStyleSheet();
protected slots:
void resetCounters();
@@ -734,5 +735,22 @@ void tst_QPushButton::hitButton()
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)
#include "tst_qpushbutton.moc"