Struct qt_gui::QCursor

source ·
#[repr(C)]
pub struct QCursor { /* private fields */ }
Expand description

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

C++ class: QCursor.

C++ documentation:

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 QGuiApplication::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 QGuiApplication, but it is not useful except as a place-holder for a real QCursor created after QGuiApplication. Attempting to use a QCursor that was created before QGuiApplication will result in a crash.

Implementations§

source§

impl QCursor

source

pub unsafe fn bitmap(&self) -> Ptr<QBitmap>

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

Calls C++ function: const QBitmap* QCursor::bitmap() const.

C++ documentation:

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

source

pub unsafe fn copy_from( &self, cursor: impl CastInto<Ref<QCursor>> ) -> Ref<QCursor>

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

Calls C++ function: QCursor& QCursor::operator=(const QCursor& cursor).

C++ documentation:

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

source

pub unsafe fn hot_spot(&self) -> CppBox<QPoint>

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

Calls C++ function: QPoint QCursor::hotSpot() const.

C++ documentation:

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

source

pub unsafe fn mask(&self) -> Ptr<QBitmap>

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

Calls C++ function: const QBitmap* QCursor::mask() const.

C++ documentation:

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

source

pub unsafe fn new() -> CppBox<QCursor>

Constructs a cursor with the default arrow shape.

Calls C++ function: [constructor] void QCursor::QCursor().

C++ documentation:

Constructs a cursor with the default arrow shape.

source

pub unsafe fn from_cursor_shape(shape: CursorShape) -> CppBox<QCursor>

Constructs a cursor with the specified shape.

Calls C++ function: [constructor] void QCursor::QCursor(Qt::CursorShape shape).

C++ documentation:

Constructs a cursor with the specified shape.

See Qt::CursorShape for a list of shapes.

See also setShape().

source

pub unsafe fn from_2_q_bitmap2_int( bitmap: impl CastInto<Ref<QBitmap>>, mask: impl CastInto<Ref<QBitmap>>, hot_x: c_int, hot_y: c_int ) -> CppBox<QCursor>

Constructs a custom bitmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QBitmap& bitmap, const QBitmap& mask, int hotX = …, int hotY = …).

C++ documentation:

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.

See also QBitmap::QBitmap() and QBitmap::setMask().

source

pub unsafe fn from_q_pixmap2_int( pixmap: impl CastInto<Ref<QPixmap>>, hot_x: c_int, hot_y: c_int ) -> CppBox<QCursor>

Constructs a custom pixmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QPixmap& pixmap, int hotX = …, int hotY = …).

C++ documentation:

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.

See also QPixmap::QPixmap() and QPixmap::setMask().

source

pub unsafe fn from_2_q_bitmap_int( bitmap: impl CastInto<Ref<QBitmap>>, mask: impl CastInto<Ref<QBitmap>>, hot_x: c_int ) -> CppBox<QCursor>

Constructs a custom bitmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QBitmap& bitmap, const QBitmap& mask, int hotX = …).

C++ documentation:

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.

See also QBitmap::QBitmap() and QBitmap::setMask().

source

pub unsafe fn from_2_q_bitmap( bitmap: impl CastInto<Ref<QBitmap>>, mask: impl CastInto<Ref<QBitmap>> ) -> CppBox<QCursor>

Constructs a custom bitmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QBitmap& bitmap, const QBitmap& mask).

C++ documentation:

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.

See also QBitmap::QBitmap() and QBitmap::setMask().

source

pub unsafe fn from_q_pixmap_int( pixmap: impl CastInto<Ref<QPixmap>>, hot_x: c_int ) -> CppBox<QCursor>

Constructs a custom pixmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QPixmap& pixmap, int hotX = …).

C++ documentation:

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.

See also QPixmap::QPixmap() and QPixmap::setMask().

source

pub unsafe fn from_q_pixmap( pixmap: impl CastInto<Ref<QPixmap>> ) -> CppBox<QCursor>

Constructs a custom pixmap cursor.

Calls C++ function: [constructor] void QCursor::QCursor(const QPixmap& pixmap).

C++ documentation:

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.

See also QPixmap::QPixmap() and QPixmap::setMask().

source

pub unsafe fn new_copy(cursor: impl CastInto<Ref<QCursor>>) -> CppBox<QCursor>

Constructs a copy of the cursor c.

Calls C++ function: [constructor] void QCursor::QCursor(const QCursor& cursor).

C++ documentation:

Constructs a copy of the cursor c.

source

pub unsafe fn pixmap(&self) -> CppBox<QPixmap>

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

Calls C++ function: QPixmap QCursor::pixmap() const.

C++ documentation:

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

source

pub unsafe fn pos_0a() -> CppBox<QPoint>

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

Calls C++ function: static QPoint QCursor::pos().

C++ documentation:

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

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

Note: The position is queried from the windowing system. If mouse events are generated via other means (e.g., via QWindowSystemInterface in a unit test), those fake mouse moves will not be reflected in the returned value.

Note: On platforms where there is no windowing system or cursors are not available, the returned position is based on the mouse move events generated via QWindowSystemInterface.

See also setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), and QGuiApplication::primaryScreen().

source

pub unsafe fn pos_1a(screen: impl CastInto<Ptr<QScreen>>) -> CppBox<QPoint>

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

Calls C++ function: static QPoint QCursor::pos(const QScreen* screen).

C++ documentation:

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

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

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

source

pub unsafe fn set_pos_2_int(x: c_int, y: c_int)

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

Calls C++ function: static void QCursor::setPos(int x, int y).

C++ documentation:

Moves the cursor (hot spot) of the primary screen 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(), and QGuiApplication::primaryScreen().

source

pub unsafe fn set_pos_q_screen2_int( screen: impl CastInto<Ptr<QScreen>>, x: c_int, y: c_int )

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

Calls C++ function: static void QCursor::setPos(QScreen* screen, int x, int y).

C++ documentation:

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

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

Note: Calling this function results in changing the cursor position through the windowing system. The windowing system will typically respond by sending mouse events to the application's window. This means that the usage of this function should be avoided in unit tests and everywhere where fake mouse events are being injected via QWindowSystemInterface because the windowing system's mouse state (with regards to buttons for example) may not match the state in the application-generated events.

Note: On platforms where there is no windowing system or cursors are not available, this function may do nothing.

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

source

pub unsafe fn set_pos_q_point(p: impl CastInto<Ref<QPoint>>)

This is an overloaded function.

Calls C++ function: static void QCursor::setPos(const QPoint& p).

C++ documentation:

This is an overloaded function.

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

source

pub unsafe fn set_pos_q_screen_q_point( screen: impl CastInto<Ptr<QScreen>>, p: impl CastInto<Ref<QPoint>> )

This is an overloaded function.

Calls C++ function: static void QCursor::setPos(QScreen* screen, const QPoint& p).

C++ documentation:

This is an overloaded function.

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

source

pub unsafe fn set_shape(&self, new_shape: CursorShape)

Sets the cursor to the shape identified by shape.

Calls C++ function: void QCursor::setShape(Qt::CursorShape newShape).

C++ documentation:

Sets the cursor to the shape identified by shape.

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

See also shape().

source

pub unsafe fn shape(&self) -> CursorShape

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

Calls C++ function: Qt::CursorShape QCursor::shape() const.

C++ documentation:

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

See also setShape().

source

pub unsafe fn swap(&self, other: impl CastInto<Ref<QCursor>>)

Swaps this cursor with the other cursor.

Calls C++ function: void QCursor::swap(QCursor& other).

C++ documentation:

Swaps this cursor with the other cursor.

source

pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>

Returns the cursor as a QVariant.

Calls C++ function: QVariant QCursor::operator QVariant() const.

C++ documentation:

Returns the cursor as a QVariant.

Trait Implementations§

source§

impl CppDeletable for QCursor

source§

unsafe fn delete(&self)

Destroys the cursor.

Calls C++ function: [destructor] void QCursor::~QCursor().

C++ documentation:

Destroys the cursor.

source§

impl PartialEq<Ref<QCursor>> for QCursor

Available on cpp_lib_version="5.11.3" or cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.
source§

fn eq(&self, rhs: &Ref<QCursor>) -> bool

Equality operator. Returns true if lhs and rhs have the same shape() and, in the case of bitmap cursors, the same hotSpot() and either the same pixmap() or the same bitmap() and mask().

Calls C++ function: bool operator==(const QCursor& lhs, const QCursor& rhs).

C++ documentation:

Equality operator. Returns true if lhs and rhs have the same shape() and, in the case of bitmap cursors, the same hotSpot() and either the same pixmap() or the same bitmap() and mask().

Note: When comparing bitmap cursors, this function only compares the bitmaps' cache keys, not each pixel.

This function was introduced in Qt 5.10.

See also operator!=(const QCursor &lhs, const QCursor &rhs).

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.