Struct qt_gui::QMouseEvent

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

The QMouseEvent class contains parameters that describe a mouse event.

C++ class: QMouseEvent.

C++ documentation:

The QMouseEvent class contains parameters that describe a mouse event.

Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved.

Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking().

Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.

A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

Note: If a mouse event is propagated to a widget for which Qt::WA_NoMousePropagation has been set, that mouse event will not be propagated further up the parent widget chain.

The state of the keyboard modifier keys can be found by calling the modifiers() function, inherited from QInputEvent.

The functions pos(), x(), and y() give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

The QWidget::setEnabled() function can be used to enable or disable mouse and keyboard events for a widget.

Reimplement the QWidget event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets.

Implementations§

source§

impl QMouseEvent

source

pub unsafe fn button(&self) -> MouseButton

Returns the button that caused the event.

Calls C++ function: Qt::MouseButton QMouseEvent::button() const.

C++ documentation:

Returns the button that caused the event.

Note that the returned value is always Qt::NoButton for mouse move events.

See also buttons() and Qt::MouseButton.

source

pub unsafe fn buttons(&self) -> QFlags<MouseButton>

Returns the button state when the event was generated. The button state is a combination of Qt::LeftButton, Qt::RightButton, Qt::MidButton using the OR operator. For mouse move events, this is all buttons that are pressed down. For mouse press and double click events this includes the button that caused the event. For mouse release events this excludes the button that caused the event.

Calls C++ function: QFlags<Qt::MouseButton> QMouseEvent::buttons() const.

C++ documentation:

Returns the button state when the event was generated. The button state is a combination of Qt::LeftButton, Qt::RightButton, Qt::MidButton using the OR operator. For mouse move events, this is all buttons that are pressed down. For mouse press and double click events this includes the button that caused the event. For mouse release events this excludes the button that caused the event.

See also button() and Qt::MouseButton.

source

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

The QMouseEvent class contains parameters that describe a mouse event.

Calls C++ function: QMouseEvent& QMouseEvent::operator=(const QMouseEvent& other).

C++ documentation:

The QMouseEvent class contains parameters that describe a mouse event.

Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved.

Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking().

Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.

A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

Note: If a mouse event is propagated to a widget for which Qt::WA_NoMousePropagation has been set, that mouse event will not be propagated further up the parent widget chain.

The state of the keyboard modifier keys can be found by calling the modifiers() function, inherited from QInputEvent.

The functions pos(), x(), and y() give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

The QWidget::setEnabled() function can be used to enable or disable mouse and keyboard events for a widget.

Reimplement the QWidget event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets.

source

pub unsafe fn flags(&self) -> QFlags<MouseEventFlag>

Returns the mouse event flags.

Calls C++ function: QFlags<Qt::MouseEventFlag> QMouseEvent::flags() const.

C++ documentation:

Returns the mouse event flags.

The mouse event flags provide additional information about a mouse event.

This function was introduced in Qt 5.3.

See also Qt::MouseEventFlag and QGraphicsSceneMouseEvent::flags().

source

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

Returns the global position of the mouse cursor at the time of the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events, globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

Calls C++ function: QPoint QMouseEvent::globalPos() const.

C++ documentation:

Returns the global position of the mouse cursor at the time of the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events, globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

See also globalX() and globalY().

source

pub unsafe fn global_x(&self) -> c_int

Returns the global x position of the mouse cursor at the time of the event.

Calls C++ function: int QMouseEvent::globalX() const.

C++ documentation:

Returns the global x position of the mouse cursor at the time of the event.

See also globalY() and globalPos().

source

pub unsafe fn global_y(&self) -> c_int

Returns the global y position of the mouse cursor at the time of the event.

Calls C++ function: int QMouseEvent::globalY() const.

C++ documentation:

Returns the global y position of the mouse cursor at the time of the event.

See also globalX() and globalPos().

source

pub unsafe fn local_pos(&self) -> Ref<QPointF>

Returns the position of the mouse cursor as a QPointF, relative to the widget or item that received the event.

Calls C++ function: const QPointF& QMouseEvent::localPos() const.

C++ documentation:

Returns the position of the mouse cursor as a QPointF, relative to the widget or item that received the event.

If you move the widget as a result of the mouse event, use the screen position returned by screenPos() to avoid a shaking motion.

This function was introduced in Qt 5.0.

See also x(), y(), windowPos(), and screenPos().

source

pub unsafe fn new_5a( type_: Type, local_pos: impl CastInto<Ref<QPointF>>, button: MouseButton, buttons: QFlags<MouseButton>, modifiers: QFlags<KeyboardModifier> ) -> CppBox<QMouseEvent>

Constructs a mouse event object.

Calls C++ function: [constructor] void QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF& localPos, Qt::MouseButton button, QFlags<Qt::MouseButton> buttons, QFlags<Qt::KeyboardModifier> modifiers).

C++ documentation:

Constructs a mouse event object.

The type parameter must be one of QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, or QEvent::MouseMove.

The localPos is the mouse cursor's position relative to the receiving widget or item. The window position is set to the same value as localPos. The button that caused the event is given as a value from the Qt::MouseButton enum. If the event type is MouseMove, the appropriate button for this event is Qt::NoButton. The mouse and keyboard states at the time of the event are specified by buttons and modifiers.

The screenPos() is initialized to QCursor::pos(), which may not be appropriate. Use the other constructor to specify the global position explicitly.

source

pub unsafe fn new_6a( type_: Type, local_pos: impl CastInto<Ref<QPointF>>, screen_pos: impl CastInto<Ref<QPointF>>, button: MouseButton, buttons: QFlags<MouseButton>, modifiers: QFlags<KeyboardModifier> ) -> CppBox<QMouseEvent>

Constructs a mouse event object.

Calls C++ function: [constructor] void QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF& localPos, const QPointF& screenPos, Qt::MouseButton button, QFlags<Qt::MouseButton> buttons, QFlags<Qt::KeyboardModifier> modifiers).

C++ documentation:

Constructs a mouse event object.

The type parameter must be QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, or QEvent::MouseMove.

The localPos is the mouse cursor's position relative to the receiving widget or item. The cursor's position in screen coordinates is specified by screenPos. The window position is set to the same value as localPos. The button that caused the event is given as a value from the Qt::MouseButton enum. If the event type is MouseMove, the appropriate button for this event is Qt::NoButton. buttons is the state of all buttons at the time of the event, modifiers the state of all keyboard modifiers.

source

pub unsafe fn new_7a( type_: Type, local_pos: impl CastInto<Ref<QPointF>>, window_pos: impl CastInto<Ref<QPointF>>, screen_pos: impl CastInto<Ref<QPointF>>, button: MouseButton, buttons: QFlags<MouseButton>, modifiers: QFlags<KeyboardModifier> ) -> CppBox<QMouseEvent>

Constructs a mouse event object.

Calls C++ function: [constructor] void QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF& localPos, const QPointF& windowPos, const QPointF& screenPos, Qt::MouseButton button, QFlags<Qt::MouseButton> buttons, QFlags<Qt::KeyboardModifier> modifiers).

C++ documentation:

Constructs a mouse event object.

The type parameter must be QEvent::MouseButtonPress, QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick, or QEvent::MouseMove.

The points localPos, windowPos and screenPos specify the mouse cursor's position relative to the receiving widget or item, window, and screen, respectively.

The button that caused the event is given as a value from the Qt::MouseButton enum. If the event type is MouseMove, the appropriate button for this event is Qt::NoButton. buttons is the state of all buttons at the time of the event, modifiers the state of all keyboard modifiers.

source

pub unsafe fn new_8a( type_: Type, local_pos: impl CastInto<Ref<QPointF>>, window_pos: impl CastInto<Ref<QPointF>>, screen_pos: impl CastInto<Ref<QPointF>>, button: MouseButton, buttons: QFlags<MouseButton>, modifiers: QFlags<KeyboardModifier>, source: MouseEventSource ) -> CppBox<QMouseEvent>

Default constructs an instance of QMouseEvent.

Calls C++ function: [constructor] void QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF& localPos, const QPointF& windowPos, const QPointF& screenPos, Qt::MouseButton button, QFlags<Qt::MouseButton> buttons, QFlags<Qt::KeyboardModifier> modifiers, Qt::MouseEventSource source).

C++ documentation:

Default constructs an instance of QMouseEvent.

source

pub unsafe fn new_copy( other: impl CastInto<Ref<QMouseEvent>> ) -> CppBox<QMouseEvent>

The QMouseEvent class contains parameters that describe a mouse event.

Calls C++ function: [constructor] void QMouseEvent::QMouseEvent(const QMouseEvent& other).

C++ documentation:

The QMouseEvent class contains parameters that describe a mouse event.

Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved.

Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking().

Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.

A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

Note: If a mouse event is propagated to a widget for which Qt::WA_NoMousePropagation has been set, that mouse event will not be propagated further up the parent widget chain.

The state of the keyboard modifier keys can be found by calling the modifiers() function, inherited from QInputEvent.

The functions pos(), x(), and y() give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

The QWidget::setEnabled() function can be used to enable or disable mouse and keyboard events for a widget.

Reimplement the QWidget event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets.

source

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

Returns the position of the mouse cursor, relative to the widget that received the event.

Calls C++ function: QPoint QMouseEvent::pos() const.

C++ documentation:

Returns the position of the mouse cursor, relative to the widget that received the event.

If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

See also x(), y(), and globalPos().

source

pub unsafe fn screen_pos(&self) -> Ref<QPointF>

Returns the position of the mouse cursor as a QPointF, relative to the screen that received the event.

Calls C++ function: const QPointF& QMouseEvent::screenPos() const.

C++ documentation:

Returns the position of the mouse cursor as a QPointF, relative to the screen that received the event.

This function was introduced in Qt 5.0.

See also x(), y(), pos(), localPos(), and windowPos().

source

pub unsafe fn set_local_pos(&self, local_position: impl CastInto<Ref<QPointF>>)

Calls C++ function: void QMouseEvent::setLocalPos(const QPointF& localPosition).

source

pub unsafe fn source(&self) -> MouseEventSource

Returns information about the mouse event source.

Calls C++ function: Qt::MouseEventSource QMouseEvent::source() const.

C++ documentation:

Returns information about the mouse event source.

The mouse event source can be used to distinguish between genuine and artificial mouse events. The latter are events that are synthesized from touch events by the operating system or Qt itself.

Note: Many platforms provide no such information. On such platforms Qt::MouseEventNotSynthesized is returned always.

This function was introduced in Qt 5.3.

See also Qt::MouseEventSource and QGraphicsSceneMouseEvent::source().

source

pub unsafe fn window_pos(&self) -> Ref<QPointF>

Returns the position of the mouse cursor as a QPointF, relative to the window that received the event.

Calls C++ function: const QPointF& QMouseEvent::windowPos() const.

C++ documentation:

Returns the position of the mouse cursor as a QPointF, relative to the window that received the event.

If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

This function was introduced in Qt 5.0.

See also x(), y(), pos(), localPos(), and screenPos().

source

pub unsafe fn x(&self) -> c_int

Returns the x position of the mouse cursor, relative to the widget that received the event.

Calls C++ function: int QMouseEvent::x() const.

C++ documentation:

Returns the x position of the mouse cursor, relative to the widget that received the event.

See also y() and pos().

source

pub unsafe fn y(&self) -> c_int

Returns the y position of the mouse cursor, relative to the widget that received the event.

Calls C++ function: int QMouseEvent::y() const.

C++ documentation:

Returns the y position of the mouse cursor, relative to the widget that received the event.

See also x() and pos().

Methods from Deref<Target = QInputEvent>§

source

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

The QInputEvent class is the base class for events that describe user input.

Calls C++ function: QInputEvent& QInputEvent::operator=(const QInputEvent& other).

C++ documentation:

The QInputEvent class is the base class for events that describe user input.

source

pub unsafe fn modifiers(&self) -> QFlags<KeyboardModifier>

Returns the keyboard modifier flags that existed immediately before the event occurred.

Calls C++ function: QFlags<Qt::KeyboardModifier> QInputEvent::modifiers() const.

C++ documentation:

Returns the keyboard modifier flags that existed immediately before the event occurred.

See also QGuiApplication::keyboardModifiers().

source

pub unsafe fn set_modifiers(&self, amodifiers: QFlags<KeyboardModifier>)

Calls C++ function: void QInputEvent::setModifiers(QFlags<Qt::KeyboardModifier> amodifiers).

source

pub unsafe fn set_timestamp(&self, atimestamp: c_ulong)

Calls C++ function: void QInputEvent::setTimestamp(unsigned long atimestamp).

source

pub unsafe fn timestamp(&self) -> c_ulong

Returns the window system's timestamp for this event. It will normally be in milliseconds since some arbitrary point in time, such as the time when the system was started.

Calls C++ function: unsigned long QInputEvent::timestamp() const.

C++ documentation:

Returns the window system’s timestamp for this event. It will normally be in milliseconds since some arbitrary point in time, such as the time when the system was started.

Methods from Deref<Target = QEvent>§

source

pub unsafe fn accept(&self)

Sets the accept flag of the event object, the equivalent of calling setAccepted(true).

Calls C++ function: void QEvent::accept().

C++ documentation:

Sets the accept flag of the event object, the equivalent of calling setAccepted(true).

Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.

See also ignore().

source

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

Calls C++ function: QEvent& QEvent::operator=(const QEvent& other).

source

pub unsafe fn ignore(&self)

Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).

Calls C++ function: void QEvent::ignore().

C++ documentation:

Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).

Clearing the accept parameter indicates that the event receiver does not want the event. Unwanted events might be propagated to the parent widget.

See also accept().

source

pub unsafe fn is_accepted(&self) -> bool

the accept flag of the event object

Calls C++ function: bool QEvent::isAccepted() const.

C++ documentation:

the accept flag of the event object

Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget. By default, isAccepted() is set to true, but don't rely on this as subclasses may choose to clear it in their constructor.

For convenience, the accept flag can also be set with accept(), and cleared with ignore().

Access functions:

bool isAccepted() const
void setAccepted(bool accepted)
source

pub unsafe fn set_accepted(&self, accepted: bool)

the accept flag of the event object

Calls C++ function: void QEvent::setAccepted(bool accepted).

C++ documentation:

the accept flag of the event object

Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget. By default, isAccepted() is set to true, but don't rely on this as subclasses may choose to clear it in their constructor.

For convenience, the accept flag can also be set with accept(), and cleared with ignore().

Access functions:

bool isAccepted() const
void setAccepted(bool accepted)
source

pub unsafe fn spontaneous(&self) -> bool

Returns true if the event originated outside the application (a system event); otherwise returns false.

Calls C++ function: bool QEvent::spontaneous() const.

C++ documentation:

Returns true if the event originated outside the application (a system event); otherwise returns false.

The return value of this function is not defined for paint events.

source

pub unsafe fn type_(&self) -> Type

Returns the event type.

Calls C++ function: QEvent::Type QEvent::type() const.

C++ documentation:

Returns the event type.

Trait Implementations§

source§

impl CppDeletable for QMouseEvent

source§

unsafe fn delete(&self)

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

source§

impl Deref for QMouseEvent

source§

fn deref(&self) -> &QInputEvent

Calls C++ function: QInputEvent* static_cast<QInputEvent*>(QMouseEvent* ptr).

§

type Target = QInputEvent

The resulting type after dereferencing.
source§

impl DynamicCast<QMouseEvent> for QEvent

source§

unsafe fn dynamic_cast(ptr: Ptr<QEvent>) -> Ptr<QMouseEvent>

Calls C++ function: QMouseEvent* dynamic_cast<QMouseEvent*>(QEvent* ptr).

source§

impl DynamicCast<QMouseEvent> for QInputEvent

source§

unsafe fn dynamic_cast(ptr: Ptr<QInputEvent>) -> Ptr<QMouseEvent>

Calls C++ function: QMouseEvent* dynamic_cast<QMouseEvent*>(QInputEvent* ptr).

source§

impl StaticDowncast<QMouseEvent> for QEvent

source§

unsafe fn static_downcast(ptr: Ptr<QEvent>) -> Ptr<QMouseEvent>

Calls C++ function: QMouseEvent* static_cast<QMouseEvent*>(QEvent* ptr).

source§

impl StaticDowncast<QMouseEvent> for QInputEvent

source§

unsafe fn static_downcast(ptr: Ptr<QInputEvent>) -> Ptr<QMouseEvent>

Calls C++ function: QMouseEvent* static_cast<QMouseEvent*>(QInputEvent* ptr).

source§

impl StaticUpcast<QEvent> for QMouseEvent

source§

unsafe fn static_upcast(ptr: Ptr<QMouseEvent>) -> Ptr<QEvent>

Calls C++ function: QEvent* static_cast<QEvent*>(QMouseEvent* ptr).

source§

impl StaticUpcast<QInputEvent> for QMouseEvent

source§

unsafe fn static_upcast(ptr: Ptr<QMouseEvent>) -> Ptr<QInputEvent>

Calls C++ function: QInputEvent* static_cast<QInputEvent*>(QMouseEvent* ptr).

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.