pub struct Cursor<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
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.
A Note for X11 Users
On X11, Qt supports the 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
-
Qt::ArrowCursor
-
left_ptr
-
Qt::SizeVerCursor
-
size_ver
-
Qt::UpArrowCursor
-
up_arrow
-
Qt::SizeHorCursor
-
size_hor
-
Qt::CrossCursor
-
cross
-
Qt::SizeBDiagCursor
-
size_bdiag
-
Qt::IBeamCursor
-
ibeam
-
Qt::SizeFDiagCursor
-
size_fdiag
-
Qt::WaitCursor
-
wait
-
Qt::SizeAllCursor
-
size_all
-
Qt::BusyCursor
-
left_ptr_watch
-
Qt::SplitVCursor
-
split_v
-
Qt::ForbiddenCursor
-
forbidden
-
Qt::SplitHCursor
-
split_h
-
Qt::PointingHandCursor
-
pointing_hand
-
Qt::OpenHandCursor
-
openhand
-
Qt::WhatsThisCursor
-
whats_this
-
Qt::ClosedHandCursor
-
closedhand
-
Qt::DragMoveCursor
-
dnd-move
ormove
-
Qt::DragCopyCursor
-
dnd-copy
orcopy
-
Qt::DragLinkCursor
-
dnd-link
orlink
See also: Widget
{fowler}{GUI Design Handbook: Cursors}
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> Cursor<'a>
impl<'a> Cursor<'a>
pub fn new() -> Cursor<'a>
sourcepub fn swap<C: CursorTrait<'a>>(&self, other: &C) -> &Self
pub fn swap<C: CursorTrait<'a>>(&self, other: &C) -> &Self
Swaps this cursor with the other cursor.
sourcepub fn shape(&self) -> CursorShape
pub fn shape(&self) -> CursorShape
Returns the cursor shape identifier. The return value is one of the Qt::CursorShape enum values (cast to an int).
See also: [set_shape()
]
sourcepub fn set_shape(&self, new_shape: CursorShape) -> &Self
pub fn set_shape(&self, new_shape: CursorShape) -> &Self
Sets the cursor to the shape identified by shape.
See Qt::CursorShape for the list of cursor shapes.
See also: [shape()
]
sourcepub fn bitmap(&self) -> Option<Bitmap<'_>>
pub fn bitmap(&self) -> Option<Bitmap<'_>>
Returns the cursor bitmap, or 0 if it is one of the standard cursors.
sourcepub fn mask(&self) -> Option<Bitmap<'_>>
pub fn mask(&self) -> Option<Bitmap<'_>>
Returns the cursor bitmap mask, or 0 if it is one of the standard cursors.
sourcepub fn pixmap(&self) -> Pixmap<'_>
pub fn pixmap(&self) -> Pixmap<'_>
Returns the cursor pixmap. This is only valid if the cursor is a pixmap cursor.
sourcepub fn hot_spot(&self) -> Point<'_>
pub fn hot_spot(&self) -> Point<'_>
Returns the cursor hot spot, or (0, 0) if it is one of the standard cursors.
sourcepub fn pos() -> Point<'a>
pub fn pos() -> Point<'a>
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: [set_pos()
]
Widget::map_from_global
Widget::map_to_global
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: [set_pos()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
sourcepub fn pos_2<S: ScreenTrait<'a>>(screen: &S) -> Point<'a>
pub fn pos_2<S: ScreenTrait<'a>>(screen: &S) -> Point<'a>
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: [set_pos()
]
Widget::map_from_global
Widget::map_to_global
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: [set_pos()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
sourcepub fn set_pos(x: i32, y: i32)
pub fn set_pos(x: i32, y: i32)
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()
]
Widget::map_from_global
Widget::map_to_global
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()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
Overloads Moves the cursor (hot spot) to the global screen position at point p.
Overloads Moves the cursor (hot spot) to the global screen position of the screen at point p.
sourcepub fn set_pos_2<S: ScreenTrait<'a>>(screen: &S, x: i32, y: i32)
pub fn set_pos_2<S: ScreenTrait<'a>>(screen: &S, x: i32, y: i32)
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()
]
Widget::map_from_global
Widget::map_to_global
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()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
Overloads Moves the cursor (hot spot) to the global screen position at point p.
Overloads Moves the cursor (hot spot) to the global screen position of the screen at point p.
sourcepub fn set_pos_3<P: PointTrait<'a>>(p: &P)
pub fn set_pos_3<P: PointTrait<'a>>(p: &P)
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()
]
Widget::map_from_global
Widget::map_to_global
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()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
Overloads Moves the cursor (hot spot) to the global screen position at point p.
Overloads Moves the cursor (hot spot) to the global screen position of the screen at point p.
sourcepub fn set_pos_4<P: PointTrait<'a>, S: ScreenTrait<'a>>(screen: &S, p: &P)
pub fn set_pos_4<P: PointTrait<'a>, S: ScreenTrait<'a>>(screen: &S, p: &P)
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()
]
Widget::map_from_global
Widget::map_to_global
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()
]
Widget::map_from_global
Widget::map_to_global
GuiApplication::primary_screen
Overloads Moves the cursor (hot spot) to the global screen position at point p.
Overloads Moves the cursor (hot spot) to the global screen position of the screen at point p.