summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qpushbutton.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/qpushbutton.cpp')
-rw-r--r--src/gui/widgets/qpushbutton.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/widgets/qpushbutton.cpp b/src/gui/widgets/qpushbutton.cpp
index 1a9adccc1c..8a18ed0ea5 100644
--- a/src/gui/widgets/qpushbutton.cpp
+++ b/src/gui/widgets/qpushbutton.cpp
@@ -58,6 +58,10 @@
#include "qdebug.h"
#include "qlayoutitem.h"
#include "qdialogbuttonbox.h"
+#ifdef Q_WS_MAC
+#include "qmacstyle_mac.h"
+#include "private/qmacstyle_mac_p.h"
+#endif // Q_WS_MAC
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
@@ -679,6 +683,37 @@ bool QPushButton::event(QEvent *e)
return QAbstractButton::event(e);
}
+#ifdef Q_WS_MAC
+/*! \reimp */
+bool QPushButton::hitButton(const QPoint &pos) const
+{
+ // This is only required if we are using the native style, so check that first.
+ QMacStyle *macStyle = qobject_cast<QMacStyle *>(style());
+ // If this is a flat button we just bail out.
+ if(isFlat() || (0 == macStyle))
+ return QAbstractButton::hitButton(pos);
+ // Now that we know we are using the native style, let's proceed.
+ Q_D(const QPushButton);
+ QPushButtonPrivate *nonConst = const_cast<QPushButtonPrivate *>(d);
+ // In OSX buttons are round, which causes the hit method to be special.
+ // We cannot simply relay on detecting if something is inside the rect or not,
+ // we need to check if it is inside the "rounded area" or not. A point might
+ // be inside the rect but not inside the rounded area.
+ // Notice this method is only reimplemented for OSX.
+ return nonConst->hitButton(pos);
+}
+
+bool QPushButtonPrivate::hitButton(const QPoint &pos)
+{
+ Q_Q(QPushButton);
+ QRect roundedRect(q->rect().left() + QMacStylePrivate::PushButtonLeftOffset,
+ q->rect().top() + QMacStylePrivate::PushButtonContentPadding,
+ q->rect().width() - QMacStylePrivate::PushButtonRightOffset,
+ q->rect().height() - QMacStylePrivate::PushButtonBottomOffset);
+ return roundedRect.contains(pos);
+}
+#endif // Q_WS_MAC
+
#ifdef QT3_SUPPORT
/*!
Use one of the constructors that doesn't take the \a name