diff options
author | Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com> | 2010-05-20 10:17:58 (GMT) |
---|---|---|
committer | Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com> | 2010-05-20 10:22:36 (GMT) |
commit | 65a673f7ab1955e277246e4c88bec46493265cf3 (patch) | |
tree | b5fe59da87a422682b2f7eaec2c66a6b5d605877 /src/gui/widgets | |
parent | 16f44ee07db46ad362a464afc2c6e6567c933870 (diff) | |
download | Qt-65a673f7ab1955e277246e4c88bec46493265cf3.zip Qt-65a673f7ab1955e277246e4c88bec46493265cf3.tar.gz Qt-65a673f7ab1955e277246e4c88bec46493265cf3.tar.bz2 |
QPushButton's click area exceeds the button area by far on Mac OS X
The problem is the "rounding" of buttons in OSX. To achieve this we
add some padding to the buttons, therefore creating an inner rect for
the widget. The common hitButton(...) method found in QAbstractButton
just checks the normal rect of the widget. What this patch does is to
reimplement hitButton(...) in QPushButton, but only for the Mac case.
In this reimplemented method I calculate the inner rect and check if
the hit point is inside that rect or not.
Task-number: QTBUG-10401
Reviewed-by: Richard Moe Gustavsen
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/qpushbutton.cpp | 34 | ||||
-rw-r--r-- | src/gui/widgets/qpushbutton.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/qpushbutton_p.h | 3 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/gui/widgets/qpushbutton.cpp b/src/gui/widgets/qpushbutton.cpp index 1a9adcc..7b8c0db 100644 --- a/src/gui/widgets/qpushbutton.cpp +++ b/src/gui/widgets/qpushbutton.cpp @@ -58,6 +58,9 @@ #include "qdebug.h" #include "qlayoutitem.h" #include "qdialogbuttonbox.h" +#ifdef Q_WS_MAC +#include "qmacstyle_mac.h" +#endif // Q_WS_MAC #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" @@ -679,6 +682,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() + QMacStyle::PushButtonLeftOffset, + q->rect().top() + QMacStyle::PushButtonContentPadding, + q->rect().width() - QMacStyle::PushButtonRightOffset, + q->rect().height() - QMacStyle::PushButtonBottomOffset); + return roundedRect.contains(pos); +} +#endif // Q_WS_MAC + #ifdef QT3_SUPPORT /*! Use one of the constructors that doesn't take the \a name diff --git a/src/gui/widgets/qpushbutton.h b/src/gui/widgets/qpushbutton.h index 2a4823d..cf28753 100644 --- a/src/gui/widgets/qpushbutton.h +++ b/src/gui/widgets/qpushbutton.h @@ -91,6 +91,9 @@ public Q_SLOTS: protected: bool event(QEvent *e); +#ifdef Q_WS_MAC + bool hitButton(const QPoint &pos) const; +#endif // Q_WS_MAC void paintEvent(QPaintEvent *); void keyPressEvent(QKeyEvent *); void focusInEvent(QFocusEvent *); diff --git a/src/gui/widgets/qpushbutton_p.h b/src/gui/widgets/qpushbutton_p.h index f2ee09d..6feb726 100644 --- a/src/gui/widgets/qpushbutton_p.h +++ b/src/gui/widgets/qpushbutton_p.h @@ -69,6 +69,9 @@ public: inline void init() { resetLayoutItemMargins(); } static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } +#ifdef Q_WS_MAC + bool hitButton(const QPoint &pos); +#endif #ifndef QT_NO_MENU QPoint adjustedMenuPosition(); #endif |