summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-12 17:05:10 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-15 11:32:09 +0200
commit757a9c21c18faad5573308d8dd85428a4519ac7d (patch)
tree0217c3d10710bb415736279766548570816feaf9
parentaaa7ab5222dee55cbd8c1bf180f8928888492a6b (diff)
QStyleSheetStyle: Fix push button hit testing with padding
Amends f9940b15f7f0fde731431626172939b9821fd660, which amended 6e1d70ae12baae4610356ec7b69635ad75a97b4e. The bevel of the button is not defined by the contentsRect, but by the borderRect that the stylesheet style calculates. Change-Id: I9a0d5bf29a06ce2270014f0d144e33cc3a1a7473 Pick-to: 5.15 Fixes: QTBUG-86587 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp7
-rw-r--r--tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp10
2 files changed, 13 insertions, 4 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index e53b81b292..472d3c05db 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -5840,8 +5840,11 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c
case SE_PushButtonBevel:
case SE_PushButtonFocusRect:
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
- if (rule.hasBox() || !rule.hasNativeBorder())
- return visualRect(opt->direction, opt->rect, rule.contentsRect(opt->rect));
+ if (rule.hasBox() || !rule.hasNativeBorder()) {
+ return visualRect(opt->direction, opt->rect, se == SE_PushButtonBevel
+ ? rule.borderRect(opt->rect)
+ : rule.contentsRect(opt->rect));
+ }
return rule.baseStyleCanDraw() ? baseStyle()->subElementRect(se, btn, w)
: QWindowsStyle::subElementRect(se, btn, w);
}
diff --git a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
index 7b4e85f823..d3314494d5 100644
--- a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
+++ b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
@@ -686,7 +686,12 @@ void tst_QPushButton::hitButton()
QVBoxLayout *layout = new QVBoxLayout;
PushButton *button1 = new PushButton("Ok");
PushButton *button2 = new PushButton("Cancel");
- button2->setStyleSheet("QPushButton { margin: 10px; border-radius: 4px; border: 1px solid black; }");
+ button2->setStyleSheet("QPushButton {"
+ "padding: 5px;"
+ "margin: 5px;"
+ "border-radius: 4px;"
+ "border: 1px solid black; }"
+ );
layout->addWidget(button1);
layout->addWidget(button2);
@@ -700,7 +705,8 @@ void tst_QPushButton::hitButton()
const QPoint button2Center = button2->rect().center();
QVERIFY(button2->hitButton(button2Center));
- QVERIFY(!button2->hitButton(QPoint(0, 0)));
+ QVERIFY(button2->hitButton(QPoint(6, 6)));
+ QVERIFY(!button2->hitButton(QPoint(2, 2)));
}
QTEST_MAIN(tst_QPushButton)