Qt 4.8
Public Functions | Static Public Functions | Properties | Friends | Related Functions | List of all members
QCursor Class Reference

The QCursor class provides a mouse cursor with an arbitrary shape. More...

#include <qcursor.h>

Public Functions

const QBitmapbitmap () const
 Returns the cursor bitmap, or 0 if it is one of the standard cursors. More...
 
HCURSOR_or_HANDLE handle () const
 Returns a platform-specific cursor handle. More...
 
QPoint hotSpot () const
 Returns the cursor hot spot, or (0, 0) if it is one of the standard cursors. More...
 
const QBitmapmask () const
 Returns the cursor bitmap mask, or 0 if it is one of the standard cursors. More...
 
 operator QVariant () const
 Returns the cursor as a QVariant. More...
 
QCursoroperator= (const QCursor &cursor)
 Assigns c to this cursor and returns a reference to this cursor. More...
 
QPixmap pixmap () const
 Returns the cursor pixmap. More...
 
 QCursor ()
 Constructs a cursor with the default arrow shape. More...
 
 QCursor (Qt::CursorShape shape)
 Constructs a cursor with the specified shape. More...
 
 QCursor (const QBitmap &bitmap, const QBitmap &mask, int hotX=-1, int hotY=-1)
 Constructs a custom bitmap cursor. More...
 
 QCursor (const QPixmap &pixmap, int hotX=-1, int hotY=-1)
 Constructs a custom pixmap cursor. More...
 
 QCursor (const QCursor &cursor)
 Constructs a copy of the cursor c. More...
 
 QCursor (HCURSOR cursor)
 Constructs a Qt cursor from the given Windows cursor. More...
 
 QCursor (Qt::HANDLE cursor)
 Constructs a Qt cursor from the given handle. More...
 
void setShape (Qt::CursorShape newShape)
 Sets the cursor to the shape identified by shape. More...
 
Qt::CursorShape shape () const
 Returns the cursor shape identifier. More...
 
 ~QCursor ()
 Destroys the cursor. More...
 

Static Public Functions

static QPoint pos ()
 Returns the position of the cursor (hot spot) in global screen coordinates. More...
 
static void setPos (int x, int y)
 Moves the cursor (hot spot) to the global screen position (x, y). More...
 
static void setPos (const QPoint &p)
 Moves the cursor (hot spot) to the global screen position at point p. More...
 

Properties

QCursorDatad
 

Friends

void * qt_mac_nsCursorForQCursor (const QCursor &c)
 
void qt_mac_set_cursor (const QCursor *c)
 
void qt_mac_updateCursorWithWidgetUnderMouse (QWidget *widgetUnderMouse)
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QCursor &cursor)
 Writes the cursor to the stream. More...
 
QDataStreamoperator>> (QDataStream &stream, QCursor &cursor)
 Reads the cursor from the stream. More...
 

Detailed Description

The QCursor class provides a mouse cursor with an arbitrary shape.

This class is mainly used to create mouse cursors that are associated with particular widgets and to get and set the position of the mouse cursor.

Qt has a number of standard cursor shapes, but you can also make custom cursor shapes based on a QBitmap, a mask and a hotspot.

To associate a cursor with a widget, use QWidget::setCursor(). To associate a cursor with all widgets (normally for a short period of time), use QApplication::setOverrideCursor().

To set a cursor shape use QCursor::setShape() or use the QCursor constructor which takes the shape as argument, or you can use one of the predefined cursors defined in the Qt::CursorShape enum.

If you want to create a cursor with your own bitmap, either use the QCursor constructor which takes a bitmap and a mask or the constructor which takes a pixmap as arguments.

To set or get the position of the mouse cursor use the static methods QCursor::pos() and QCursor::setPos().

Note: It is possible to create a QCursor before QApplication, but it is not useful except as a place-holder for a real QCursor created after QApplication. Attempting to use a QCursor that was created before QApplication will result in a crash.

A Note for X11 Users

On X11, Qt supports the http://www.xfree86.org/4.3.0/Xcursor.3.html Xcursor library, which allows for full color icon themes. The table below shows the cursor name used for each Qt::CursorShape value. If a cursor cannot be found using the name shown below, a standard X11 cursor will be used instead. Note: X11 does not provide appropriate cursors for all possible Qt::CursorShape values. It is possible that some cursors will be taken from the Xcursor theme, while others will use an internal bitmap cursor.

Shape Qt::CursorShape Value Cursor Name Shape Qt::CursorShape Value Cursor Name
cursor-arrow.png
Qt::ArrowCursor left_ptr
cursor-sizev.png
Qt::SizeVerCursor size_ver
cursor-uparrow.png
Qt::UpArrowCursor up_arrow
cursor-sizeh.png
Qt::SizeHorCursor size_hor
cursor-cross.png
Qt::CrossCursor cross
cursor-sizeb.png
Qt::SizeBDiagCursor size_bdiag
cursor-ibeam.png
Qt::IBeamCursor ibeam
cursor-sizef.png
Qt::SizeFDiagCursor size_fdiag
cursor-wait.png
Qt::WaitCursor wait
cursor-sizeall.png
Qt::SizeAllCursor size_all
cursor-busy.png
Qt::BusyCursor left_ptr_watch
cursor-vsplit.png
Qt::SplitVCursor split_v
cursor-forbidden.png
Qt::ForbiddenCursor forbidden
cursor-hsplit.png
Qt::SplitHCursor split_h
cursor-hand.png
Qt::PointingHandCursor pointing_hand
cursor-openhand.png
Qt::OpenHandCursor openhand
cursor-whatsthis.png
Qt::WhatsThisCursor whats_this
cursor-closedhand.png
Qt::ClosedHandCursor closedhand
Qt::DragMoveCursor dnd-move or move Qt::DragCopyCursor dnd-copy or copy
Qt::DragLinkCursor dnd-link or link
See also
QWidget, {fowler}{GUI Design Handbook: Cursors}

Definition at line 89 of file qcursor.h.

Constructors and Destructors

◆ QCursor() [1/7]

QCursor::QCursor ( )

Constructs a cursor with the default arrow shape.

Definition at line 433 of file qcursor.cpp.

434 {
436  if (QApplication::startingUp()) {
437  d = 0;
438  return;
439  }
441  }
443  c->ref.ref();
444  d = c;
445 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool ref()
Atomically increments the value of this QAtomicInt.
static bool initialized
Definition: qcursor_p.h:125
QCursorData * qt_cursorTable[Qt::LastCursor+1]
Definition: qcursor.cpp:398
static bool startingUp()
Returns true if an application object has not been created yet; otherwise returns false...
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87

◆ QCursor() [2/7]

QCursor::QCursor ( Qt::CursorShape  shape)

Constructs a cursor with the specified shape.

See Qt::CursorShape for a list of shapes.

See also
setShape()

Definition at line 454 of file qcursor.cpp.

455  : d(0)
456 {
459  setShape(shape);
460 }
static bool initialized
Definition: qcursor_p.h:125
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
void setShape(Qt::CursorShape newShape)
Sets the cursor to the shape identified by shape.
Definition: qcursor.cpp:483
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469

◆ QCursor() [3/7]

QCursor::QCursor ( const QBitmap bitmap,
const QBitmap mask,
int  hotX = -1,
int  hotY = -1 
)

Constructs a custom bitmap cursor.

bitmap and mask make up the bitmap. hotX and hotY define the cursor's hot spot.

If hotX is negative, it is set to the bitmap().width()/2. If hotY is negative, it is set to the bitmap().height()/2.

The cursor bitmap (B) and mask (M) bits are combined like this:

  • B=1 and M=1 gives black.
  • B=0 and M=1 gives white.
  • B=0 and M=0 gives transparent.
  • B=1 and M=0 gives an XOR'd result under Windows, undefined results on all other platforms.

Use the global Qt color Qt::color0 to draw 0-pixels and Qt::color1 to draw 1-pixels in the bitmaps.

Valid cursor sizes depend on the display hardware (or the underlying window system). We recommend using 32 x 32 cursors, because this size is supported on all platforms. Some platforms also support 16 x 16, 48 x 48, and 64 x 64 cursors.

Note
On Windows CE, the cursor size is fixed. If the pixmap is bigger than the system size, it will be scaled.
See also
QBitmap::QBitmap(), QBitmap::setMask()

Definition at line 392 of file qcursor.cpp.

393  : d(0)
394 {
395  d = QCursorData::setBitmap(bitmap, mask, hotX, hotY);
396 }
static QCursorData * setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
Definition: qcursor_mac.mm:278
QCursorData * d
Definition: qcursor.h:141

◆ QCursor() [4/7]

QCursor::QCursor ( const QPixmap pixmap,
int  hotX = -1,
int  hotY = -1 
)

Constructs a custom pixmap cursor.

pixmap is the image. It is usual to give it a mask (set using QPixmap::setMask()). hotX and hotY define the cursor's hot spot.

If hotX is negative, it is set to the pixmap().width()/2. If hotY is negative, it is set to the pixmap().height()/2.

Valid cursor sizes depend on the display hardware (or the underlying window system). We recommend using 32 x 32 cursors, because this size is supported on all platforms. Some platforms also support 16 x 16, 48 x 48, and 64 x 64 cursors.

Note
On Windows CE, the cursor size is fixed. If the pixmap is bigger than the system size, it will be scaled.
See also
QPixmap::QPixmap(), QPixmap::setMask()

Definition at line 333 of file qcursor.cpp.

334  : d(0)
335 {
338  QBitmap bmm = pixmap.mask();
339  if (!bmm.isNull()) {
340  QBitmap nullBm;
341  bm.setMask(nullBm);
342  }
343  else if (!pixmap.mask().isNull()) {
346  }
347  else {
348  bmm = QBitmap(bm.size());
349  bmm.fill(Qt::color1);
350  }
351 
352  d = QCursorData::setBitmap(bm, bmm, hotX, hotY);
353  d->pixmap = pixmap;
354 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QPixmap pixmap
Definition: qcursor_p.h:90
void setMask(const QBitmap &)
Sets a mask bitmap.
Definition: qpixmap.cpp:822
static QCursorData * setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
Definition: qcursor_mac.mm:278
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
QPixmap pixmap() const
Returns the cursor pixmap.
Definition: qcursor.cpp:528
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
QCursorData * d
Definition: qcursor.h:141
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ QCursor() [5/7]

QCursor::QCursor ( const QCursor cursor)

Constructs a copy of the cursor c.

Definition at line 551 of file qcursor.cpp.

552 {
555  d = c.d;
556  d->ref.ref();
557 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool ref()
Atomically increments the value of this QAtomicInt.
static bool initialized
Definition: qcursor_p.h:125
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87

◆ ~QCursor()

QCursor::~QCursor ( )

Destroys the cursor.

Definition at line 563 of file qcursor.cpp.

564 {
565  if (d && !d->ref.deref())
566  delete d;
567 }
bool deref()
Atomically decrements the value of this QAtomicInt.
QCursorData * d
Definition: qcursor.h:141
QAtomicInt ref
Definition: qcursor_p.h:87

◆ QCursor() [6/7]

QCursor::QCursor ( HCURSOR  cursor)

Constructs a Qt cursor from the given Windows cursor.

Warning
This function is only available on Windows.
See also
handle()

Definition at line 104 of file qcursor_win.cpp.

105 {
107  d->hcurs = handle;
108 }
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
HCURSOR hcurs
Definition: qcursor_p.h:98
QCursorData * d
Definition: qcursor.h:141

◆ QCursor() [7/7]

QCursor::QCursor ( Qt::HANDLE  handle)

Constructs a Qt cursor from the given handle.

Warning
This function is only available on X11.
See also
handle()

Definition at line 100 of file qcursor_x11.cpp.

101 {
105  d->hcurs = cursor;
106 }
static bool initialized
Definition: qcursor_p.h:125
HCURSOR hcurs
Definition: qcursor_p.h:98
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417

Functions

◆ bitmap()

const QBitmap * QCursor::bitmap ( ) const

Returns the cursor bitmap, or 0 if it is one of the standard cursors.

Definition at line 504 of file qcursor.cpp.

Referenced by QXlibCursor::createCursorBitmap(), and operator<<().

505 {
508  return d->bm;
509 }
static bool initialized
Definition: qcursor_p.h:125
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
QBitmap * bm
Definition: qcursor_p.h:89

◆ handle()

Qt::HANDLE QCursor::handle ( ) const

Returns a platform-specific cursor handle.

The HCURSOR_or_HANDLE type is HCURSOR on Windows and Qt::HANDLE on X11 and Mac OS X. On Qt for Embedded Linux it is an integer.

Warning
Using the value returned by this function is not portable.

Definition at line 301 of file qcursor_mac.mm.

Referenced by QXlibCursor::changeCursor(), effectiveState(), isServerProcess(), parseGeometry(), QGuiEventDispatcherWin32::processEvents(), QCursor(), qJournalRecordProc(), qstring_to_xtp(), qt_grab_cursor(), qt_mac_set_cursor(), qt_try_modal(), qt_win_set_cursor(), qt_x11_enforce_cursor(), QtWndProc(), QApplication::qwsProcessEvent(), and QETWidget::translateMouseEvent().

302 {
305  if(d->type == QCursorData::TYPE_None)
306  d->update();
307  return (Qt::HANDLE)d->mId;
308 }
static bool initialized
Definition: qcursor_p.h:125
void * HANDLE
Definition: qnamespace.h:1671
void update()
Creates the cursor.
Definition: qcursor_mac.mm:387
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417

◆ hotSpot()

QPoint QCursor::hotSpot ( ) const

Returns the cursor hot spot, or (0, 0) if it is one of the standard cursors.

Definition at line 540 of file qcursor.cpp.

Referenced by QDirectFBCursor::changeCursor(), QPlatformSoftwareCursor::changeCursor(), QXlibCursor::createCursorBitmap(), and operator<<().

541 {
544  return QPoint(d->hx, d->hy);
545 }
short hy
Definition: qcursor_p.h:91
static bool initialized
Definition: qcursor_p.h:125
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QCursorData * d
Definition: qcursor.h:141
short hx
Definition: qcursor_p.h:91
static void initialize()
Definition: qcursor.cpp:417

◆ mask()

const QBitmap * QCursor::mask ( ) const

Returns the cursor bitmap mask, or 0 if it is one of the standard cursors.

Definition at line 516 of file qcursor.cpp.

Referenced by QXlibCursor::createCursorBitmap(), and operator<<().

517 {
520  return d->bmm;
521 }
static bool initialized
Definition: qcursor_p.h:125
QCursorData * d
Definition: qcursor.h:141
QBitmap * bmm
Definition: qcursor_p.h:89
static void initialize()
Definition: qcursor.cpp:417

◆ operator QVariant()

QCursor::operator QVariant ( ) const

Returns the cursor as a QVariant.

Definition at line 590 of file qcursor.cpp.

591 {
592  return QVariant(QVariant::Cursor, this);
593 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator=()

QCursor & QCursor::operator= ( const QCursor cursor)

Assigns c to this cursor and returns a reference to this cursor.

Definition at line 575 of file qcursor.cpp.

576 {
579  if (c.d)
580  c.d->ref.ref();
581  if (d && !d->ref.deref())
582  delete d;
583  d = c.d;
584  return *this;
585 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static bool initialized
Definition: qcursor_p.h:125
bool deref()
Atomically decrements the value of this QAtomicInt.
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87

◆ pixmap()

QPixmap QCursor::pixmap ( ) const

Returns the cursor pixmap.

This is only valid if the cursor is a pixmap cursor.

Definition at line 528 of file qcursor.cpp.

Referenced by QDirectFBCursor::changeCursor(), QPlatformSoftwareCursor::changeCursor(), operator<<(), and QCursor().

529 {
532  return d->pixmap;
533 }
QPixmap pixmap
Definition: qcursor_p.h:90
static bool initialized
Definition: qcursor_p.h:125
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417

◆ pos()

QPoint QCursor::pos ( )
static

Returns the position of the cursor (hot spot) in global screen coordinates.

You can call QWidget::mapFromGlobal() to translate it to widget coordinates.

See also
setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()

Definition at line 310 of file qcursor_mac.mm.

Referenced by QDialog::adjustPosition(), QGraphicsViewPrivate::centerView(), QApplicationPrivate::dispatchEnterLeave(), QX11Data::dndEnable(), QAbstractItemView::doAutoScroll(), QWidgetResizeHandler::doMove(), QWidgetResizeHandler::doResize(), QTreeView::drawTree(), QShortcut::event(), QDockWidget::event(), QToolBar::event(), findRealWindow(), QSystemTrayIconSys::findTrayGeometry(), QPlatformSoftwareCursor::getCurrentRect(), QApplicationPrivate::globalEventProcessor(), QAbstractItemView::horizontalScrollbarValueChanged(), QColorDialogPrivate::init(), QFontDialogPrivate::init(), QMenu::internalDelayedPopup(), QGraphicsItem::isUnderMouse(), QWidgetResizeHandler::keyPressEvent(), QApplicationPrivate::leaveModal_sys(), QGraphicsScenePrivate::leaveScene(), QWorkspaceTitleBar::paintEvent(), QMenu::popup(), QContextMenuEvent::QContextMenuEvent(), QCursor(), QMouseEvent::QMouseEvent(), qt_keyrelease_scanner(), qt_mac_update_cursor(), qt_qpa_set_cursor(), QtWndProc(), QWhatsThisPrivate::QWhatsThisPrivate(), QWheelEvent::QWheelEvent(), QMacPinchGestureRecognizer::reset(), QApplicationPrivate::sendSyntheticEnterLeave(), QGraphicsItem::setCursor(), QHeaderView::setOffset(), QTextBrowserPrivate::setSource(), QWizard::sizeHint(), QTreeView::timerEvent(), QPlainTextEdit::timerEvent(), QTextEdit::timerEvent(), QGraphicsItem::unsetCursor(), QMessageBoxPrivate::updateSize(), QAbstractItemView::verticalScrollbarValueChanged(), QSystemTrayIconSys::winEvent(), QApplication::x11EventFilter(), QMouseEvent::~QMouseEvent(), and QWheelEvent::~QWheelEvent().

311 {
312  return flipPoint([NSEvent mouseLocation]).toPoint();
313 }
QPointF flipPoint(const NSPoint &p)
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376

◆ setPos() [1/2]

void QCursor::setPos ( int  x,
int  y 
)
static

Moves the cursor (hot spot) to the global screen position (x, y).

You can call QWidget::mapToGlobal() to translate widget coordinates to global screen coordinates.

See also
pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()

Definition at line 315 of file qcursor_mac.mm.

Referenced by QBBScreenEventHandler::handleTouchEvent(), QWidgetResizeHandler::keyPressEvent(), QMdiSubWindow::keyPressEvent(), QTest::mouseEvent(), QCursor(), QHeaderView::setOffset(), and QDialog::setVisible().

316 {
317 #ifdef QT_MAC_USE_COCOA
318  CGPoint pos;
319  pos.x = x;
320  pos.y = y;
321 
322  CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
323  CGEventPost(kCGHIDEventTap, e);
324  CFRelease(e);
325 #else
326  CGWarpMouseCursorPosition(CGPointMake(x, y));
327 
328  /* I'm not too keen on doing this, but this makes it a lot easier, so I just
329  send the event back through the event system and let it get propagated correctly
330  ideally this would not really need to be faked --Sam
331  */
332  QWidget *widget = 0;
333  if(QWidget *grb = QWidget::mouseGrabber())
334  widget = grb;
335  else
336  widget = QApplication::widgetAt(QPoint(x, y));
337  if(widget) {
340  qt_sendSpontaneousEvent(widget, &me);
341  }
342 #endif
343 }
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
static QWidget * mouseGrabber()
Returns the widget that is currently grabbing the mouse input.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310

◆ setPos() [2/2]

void QCursor::setPos ( const QPoint p)
inlinestatic

Moves the cursor (hot spot) to the global screen position at point p.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 115 of file qcursor.h.

Referenced by setPos().

115 { setPos(p.x(), p.y()); }
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ setShape()

void QCursor::setShape ( Qt::CursorShape  shape)

Sets the cursor to the shape identified by shape.

See Qt::CursorShape for the list of cursor shapes.

See also
shape()

Definition at line 483 of file qcursor.cpp.

Referenced by operator>>(), and QCursor().

484 {
488  if (!c)
489  c = qt_cursorTable[0];
490  c->ref.ref();
491  if (!d) {
492  d = c;
493  } else {
494  if (!d->ref.deref())
495  delete d;
496  d = c;
497  }
498 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool ref()
Atomically increments the value of this QAtomicInt.
static bool initialized
Definition: qcursor_p.h:125
bool deref()
Atomically decrements the value of this QAtomicInt.
unsigned int uint
Definition: qglobal.h:996
QCursorData * qt_cursorTable[Qt::LastCursor+1]
Definition: qcursor.cpp:398
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417
QAtomicInt ref
Definition: qcursor_p.h:87
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469

◆ shape()

Qt::CursorShape QCursor::shape ( ) const

Returns the cursor shape identifier.

The return value is one of the Qt::CursorShape enum values (cast to an int).

See also
setShape()

Definition at line 469 of file qcursor.cpp.

Referenced by QTextBrowserPrivate::_q_highlightLink(), QWaylandCursor::changeCursor(), QXlibCursor::changeCursor(), QDirectFBCursor::changeCursor(), QPlatformSoftwareCursor::changeCursor(), QCursorData::cleanup(), QScriptEdit::extraAreaMouseEvent(), QCursorData::initialize(), QHeaderView::mouseDoubleClickEvent(), operator<<(), QWidget::setCursor(), and setShape().

470 {
473  return d->cshape;
474 }
static bool initialized
Definition: qcursor_p.h:125
Qt::CursorShape cshape
Definition: qcursor_p.h:88
QCursorData * d
Definition: qcursor.h:141
static void initialize()
Definition: qcursor.cpp:417

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QCursor cursor 
)
related

Writes the cursor to the stream.

See also
{Serializing Qt Data Types}

Definition at line 255 of file qcursor.cpp.

256 {
257  s << (qint16)c.shape(); // write shape id to stream
258  if (c.shape() == Qt::BitmapCursor) { // bitmap cursor
259  bool isPixmap = false;
260  if (s.version() >= 7) {
261  isPixmap = !c.pixmap().isNull();
262  s << isPixmap;
263  }
264  if (isPixmap)
265  s << c.pixmap();
266  else
267  s << *c.bitmap() << *c.mask();
268  s << c.hotSpot();
269  }
270  return s;
271 }
unsigned char c[8]
Definition: qnumeric_p.h:62
short qint16
Definition: qglobal.h:935

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QCursor cursor 
)
related

Reads the cursor from the stream.

See also
{Serializing Qt Data Types}

Definition at line 285 of file qcursor.cpp.

286 {
287  qint16 shape;
288  s >> shape; // read shape id from stream
289  if (shape == Qt::BitmapCursor) { // read bitmap cursor
290  bool isPixmap = false;
291  if (s.version() >= 7)
292  s >> isPixmap;
293  if (isPixmap) {
294  QPixmap pm;
295  QPoint hot;
296  s >> pm >> hot;
297  c = QCursor(pm, hot.x(), hot.y());
298  } else {
299  QBitmap bm, bmm;
300  QPoint hot;
301  s >> bm >> bmm >> hot;
302  c = QCursor(bm, bmm, hot.x(), hot.y());
303  }
304  } else {
305  c.setShape((Qt::CursorShape)shape); // create cursor with shape
306  }
307  return s;
308 }
unsigned char c[8]
Definition: qnumeric_p.h:62
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
short qint16
Definition: qglobal.h:935
CursorShape
Definition: qnamespace.h:1262
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QCursor()
Constructs a cursor with the default arrow shape.
Definition: qcursor.cpp:433
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469

◆ qt_mac_nsCursorForQCursor

void* qt_mac_nsCursorForQCursor ( const QCursor c)
friend

Definition at line 100 of file qcursor_mac.mm.

101 {
102  c.d->update();
103  return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease];
104 }
void update()
Creates the cursor.
Definition: qcursor_mac.mm:387
QCursorData * d
Definition: qcursor.h:141

◆ qt_mac_set_cursor

void qt_mac_set_cursor ( const QCursor c)
friend

Definition at line 108 of file qcursor_mac.mm.

109 {
110 #ifdef QT_MAC_USE_COCOA
112  [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*c)) set];
113 #else
114  if (!c) {
115  currentCursor = 0;
116  return;
117  }
118  c->handle(); //force the cursor to get loaded, if it's not
119 
120  if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor
121  && currentCursor->curs.tc.anim)
122  currentCursor->curs.tc.anim->stop();
123  if(c->d->type == QCursorData::TYPE_ImageCursor) {
124  [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set];
125  } else if(c->d->type == QCursorData::TYPE_ThemeCursor) {
126  if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) {
127  SetThemeCursor(c->d->curs.tc.curs);
128  } else {
129  if(!c->d->curs.tc.anim)
130  c->d->curs.tc.anim = new QMacAnimateCursor;
131  c->d->curs.tc.anim->start(c->d->curs.tc.curs);
132  }
133  }
134 
135  currentCursor = c->d;
136 #endif
137 }
HCURSOR_or_HANDLE handle() const
Returns a platform-specific cursor handle.
Definition: qcursor_mac.mm:301
static QCursorData * currentCursor
Definition: qcursor_mac.mm:106
friend void * qt_mac_nsCursorForQCursor(const QCursor &c)
Definition: qcursor_mac.mm:100
QCursorData * d
Definition: qcursor.h:141

◆ qt_mac_updateCursorWithWidgetUnderMouse

void qt_mac_updateCursorWithWidgetUnderMouse ( QWidget widgetUnderMouse)
friend

Definition at line 144 of file qcursor_mac.mm.

145 {
146  QCursor cursor(Qt::ArrowCursor);
147  if (qt_button_down) {
148  // The widget that is currently pressed
149  // grabs the mouse cursor:
150  widgetUnderMouse = qt_button_down;
152  } else if (qt_button_down_on_prev_call) {
153  // Grab has been released, so do
154  // a full check:
158  }
159 
161  cursor = *QApplication::overrideCursor();
162  } else if (grabCursor) {
163  cursor = *grabCursor;
164  } else if (widgetUnderMouse) {
165  if (widgetUnderMouse == lastWidgetUnderMouse) {
166  // Optimization that should hit when the widget under
167  // the mouse does not change as the mouse moves:
169  cursor = lastMouseCursorWidget->cursor();
170  } else {
171  QWidget *w = widgetUnderMouse;
172  for (; w; w = w->parentWidget()) {
174  cursor = w->cursor();
175  break;
176  }
177  if (w->isWindow())
178  break;
179  }
180  // One final check in case we ran out of parents in the loop:
181  if (w && !w->testAttribute(Qt::WA_SetCursor))
182  w = 0;
183 
184  lastWidgetUnderMouse = widgetUnderMouse;
186  }
187  }
188 
189 #ifdef QT_MAC_USE_COCOA
190  cursor.d->update();
191  NSCursor *nsCursor = static_cast<NSCursor *>(cursor.d->curs.cp.nscursor);
192  if ([NSCursor currentCursor] != nsCursor) {
194  [nsCursor set];
195  }
196 #else
197  qt_mac_set_cursor(&cursor);
198 #endif
199 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
friend void qt_mac_set_cursor(const QCursor *c)
Definition: qcursor_mac.mm:108
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
static QPointer< QWidget > lastWidgetUnderMouse
Definition: qcursor_mac.mm:139
static QPointer< QWidget > lastMouseCursorWidget
Definition: qcursor_mac.mm:140
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
static QCursor * overrideCursor()
Strips out vertical alignment flags and transforms an alignment align of Qt::AlignLeft into Qt::Align...
static QCursorData * currentCursor
Definition: qcursor_mac.mm:106
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
static bool qt_button_down_on_prev_call
Definition: qcursor_mac.mm:141
static QCursor * grabCursor
Definition: qcursor_mac.mm:142
QPointer< QWidget > qt_button_down

Properties

◆ d

QCursorData* QCursor::d
private

The documentation for this class was generated from the following files: