Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QCursor Class

TheQCursor class provides a mouse cursor with an arbitrary shape.More...

Header:#include <QCursor>

Public Functions

QCursor()
QCursor(Qt::CursorShape shape)
QCursor(const QBitmap & bitmap, const QBitmap & mask, int hotX = -1, int hotY = -1)
QCursor(const QPixmap & pixmap, int hotX = -1, int hotY = -1)
QCursor(const QCursor & c)
QCursor(HCURSOR cursor)
QCursor(Qt::HANDLE handle)
~QCursor()
const QBitmap *bitmap() const
HCURSOR_or_HANDLEhandle() const
QPointhotSpot() const
const QBitmap *mask() const
QPixmappixmap() const
voidsetShape(Qt::CursorShape shape)
Qt::CursorShapeshape() const
operator QVariant() const
QCursor &operator=(const QCursor & c)
QCursor &operator=(QCursor && other)

Static Public Members

QPointpos()
voidsetPos(int x, int y)
voidsetPos(const QPoint & p)

Related Non-Members

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

Detailed Description

TheQCursor 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 aQBitmap, a mask and a hotspot.

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

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

If you want to create a cursor with your own bitmap, either use theQCursor 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 methodsQCursor::pos() andQCursor::setPos().

Note: It is possible to create aQCursor beforeQApplication, but it is not useful except as a place-holder for a realQCursor created afterQApplication. Attempting to use aQCursor that was created beforeQApplication will result in a crash.

A Note for X11 Users

On X11, Qt supports theXcursor library, which allows for full color icon themes. The table below shows the cursor name used for eachQt::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 possibleQt::CursorShape values. It is possible that some cursors will be taken from the Xcursor theme, while others will use an internal bitmap cursor.

See alsoQWidget andGUI Design Handbook: Cursors.

Member Function Documentation

QCursor::QCursor()

Constructs a cursor with the default arrow shape.

QCursor::QCursor(Qt::CursorShape shape)

Constructs a cursor with the specifiedshape.

SeeQt::CursorShape for a list of shapes.

See alsosetShape().

QCursor::QCursor(constQBitmap & bitmap, constQBitmap & mask,int hotX = -1,int hotY = -1)

Constructs a custom bitmap cursor.

bitmap andmask make up the bitmap.hotX andhotY define the cursor's hot spot.

IfhotX is negative, it is set to thebitmap().width()/2. IfhotY is negative, it is set to thebitmap().height()/2.

The cursorbitmap (B) andmask (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 colorQt::color0 to draw 0-pixels andQt::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 alsoQBitmap::QBitmap() andQBitmap::setMask().

QCursor::QCursor(constQPixmap & 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 usingQPixmap::setMask()).hotX andhotY define the cursor's hot spot.

IfhotX is negative, it is set to thepixmap().width()/2. IfhotY is negative, it is set to thepixmap().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 alsoQPixmap::QPixmap() andQPixmap::setMask().

QCursor::QCursor(constQCursor & c)

Constructs a copy of the cursorc.

QCursor::QCursor(HCURSOR cursor)

Constructs a Qt cursor from the given Windowscursor.

Warning: This function is only available on Windows.

See alsohandle().

QCursor::QCursor(Qt::HANDLE handle)

Constructs a Qt cursor from the givenhandle.

Warning: This function is only available on X11.

See alsohandle().

QCursor::~QCursor()

Destroys the cursor.

constQBitmap * QCursor::bitmap() const

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

HCURSOR_or_HANDLE QCursor::handle() const

Returns a platform-specific cursor handle. TheHCURSOR_or_HANDLE type isHCURSOR on Windows andQt::HANDLE on X11 and Mac OS X. OnQt for Embedded Linux it is an integer.

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

QPoint QCursor::hotSpot() const

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

constQBitmap * QCursor::mask() const

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

QPixmap QCursor::pixmap() const

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

[static]QPoint QCursor::pos()

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

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

See alsosetPos(),QWidget::mapFromGlobal(), andQWidget::mapToGlobal().

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

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

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

See alsopos(),QWidget::mapFromGlobal(), andQWidget::mapToGlobal().

[static]void QCursor::setPos(constQPoint & p)

This is an overloaded function.

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

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

Sets the cursor to the shape identified byshape.

SeeQt::CursorShape for the list of cursor shapes.

See alsoshape().

Qt::CursorShape QCursor::shape() const

Returns the cursor shape identifier. The return value is one of theQt::CursorShape enum values (cast to an int).

See alsosetShape().

QCursor::operator QVariant() const

Returns the cursor as aQVariant.

QCursor & QCursor::operator=(constQCursor & c)

Assignsc to this cursor and returns a reference to this cursor.

QCursor & QCursor::operator=(QCursor && other)

Related Non-Members

QDataStream &operator<<(QDataStream & stream, constQCursor & cursor)

Writes thecursor to thestream.

See alsoSerializing Qt Data Types.

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

Reads thecursor from thestream.

See alsoSerializing Qt Data Types.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp