diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2012-05-03 14:58:25 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-04 13:02:00 +0200 |
commit | 5190beae8166e615d2f910109cf081505ebe6807 (patch) | |
tree | ee5bd601feefda73847a47f446001fc9ea1a9b69 /src/gui/kernel/qwindow.cpp | |
parent | 5c2a055230e8c3a2bcd0f7f6f601d6c618774a8b (diff) |
Add setCursor API to QWindow
Change-Id: Id430ea9c94475356c9367a135f678f5f9ef795fc
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 2117835609..8b37fce50c 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -59,6 +59,7 @@ #include <QtCore/QDebug> #include <QStyleHints> +#include <QPlatformCursor> QT_BEGIN_NAMESPACE @@ -1684,4 +1685,64 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed() } +/*! + \property QWindow::cursor + \brief the cursor shape for this window + + The mouse cursor will assume this shape when it is over this + window, unless an override cursor is set. See the \link + Qt::CursorShape list of predefined cursor objects\endlink for a + range of useful shapes. + + By default, this property contains a cursor with the Qt::ArrowCursor + shape. + + Some underlying window implementations will reset the cursor if it + leaves a window even if the mouse is grabbed. If you want to have + a cursor set for all windows, even when outside the window, consider + QGuiApplication::setOverrideCursor(). + + \sa QGuiApplication::setOverrideCursor() +*/ + +#ifndef QT_NO_CURSOR +QCursor QWindow::cursor() const +{ + Q_D(const QWindow); + return d->cursor; +} + +void QWindow::setCursor(const QCursor &cursor) +{ + Q_D(QWindow); + if (QPlatformCursor *platformCursor = d->screen->handle()->cursor()) { + d->cursor = cursor; + QCursor *oc = QGuiApplication::overrideCursor(); + QCursor c = oc ? *oc : d->cursor; + platformCursor->changeCursor(&c, this); + QEvent event(QEvent::CursorChange); + QGuiApplication::sendEvent(this, &event); + } +} + +/*! + \brief Restores the default arrow cursor for this window. + */ +void QWindow::unsetCursor() +{ + Q_D(QWindow); + if (QPlatformCursor *platformCursor = d->screen->handle()->cursor()) { + d->cursor = Qt::ArrowCursor; + QCursor *oc = QGuiApplication::overrideCursor(); + if (!oc) { + QCursor c = d->cursor; + platformCursor->changeCursor(&c, this); + } + QEvent event(QEvent::CursorChange); + QGuiApplication::sendEvent(this, &event); + } +} + +#endif + QT_END_NAMESPACE |