From 6e1d70ae12baae4610356ec7b69635ad75a97b4e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 22 Jan 2020 13:51:01 +0100 Subject: QPushButton: only trigger button when click occurs within the bevel rect On the mac, the push button's bevel doesn't cover the entire widget rectangle, but is smaller to leave space for focus frame, shadow, and in general to meet style guidelines. Without this change, a click anywhere inside the widget would activate the button. QAbstractButton::hitButton can be reimplemented to limit the area in which the button is triggered. However, getting the rectangle also requires an addition to QStyle, so that we can query QStyle::subElementRect for the actual area the button's bevel covers. As a side effect, tests that use QPushButton and assume that it responds to clicks at position 0,0 have to be fixed so that they don't fail on mac. Change-Id: I01b60a763bccf39090aee5b2369af300f922d226 Fixes: QTBUG-81452 Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qstyle.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets/styles/qstyle.cpp') diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 72e40d657d..987465efae 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1012,6 +1012,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SE_PushButtonFocusRect Area for the focus rect (usually larger than the contents rect). \value SE_PushButtonLayoutItem Area that counts for the parent layout. + \value SE_PushButtonBevel Area used for the bevel of the button. \value SE_CheckBoxIndicator Area for the state indicator (e.g., check mark). \value SE_CheckBoxContents Area for the label (text or pixmap). @@ -1120,6 +1121,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \header \li Sub Element \li QStyleOption Subclass \row \li \l SE_PushButtonContents \li \l QStyleOptionButton \row \li \l SE_PushButtonFocusRect \li \l QStyleOptionButton + \row \li \l SE_PushButtonBevel \li \l QStyleOptionButton \row \li \l SE_CheckBoxIndicator \li \l QStyleOptionButton \row \li \l SE_CheckBoxContents \li \l QStyleOptionButton \row \li \l SE_CheckBoxFocusRect \li \l QStyleOptionButton -- cgit v1.2.3