[][src]Struct qt_gui::QDrag

#[repr(C)]pub struct QDrag { /* fields omitted */ }

The QDrag class provides support for MIME-based drag and drop data transfer.

C++ class: QDrag.

C++ documentation:

The QDrag class provides support for MIME-based drag and drop data transfer.

Drag and drop is an intuitive way for users to copy or move data around in an application, and is used in many desktop environments as a mechanism for copying data between applications. Drag and drop support in Qt is centered around the QDrag class that handles most of the details of a drag and drop operation.

The data to be transferred by the drag and drop operation is contained in a QMimeData object. This is specified with the setMimeData() function in the following way:

QDrag drag = new QDrag(this); QMimeData mimeData = new QMimeData;

mimeData->setText(commentEdit->toPlainText()); drag->setMimeData(mimeData);

Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. The QDrag must be constructed on the heap with a parent QObject to ensure that Qt can clean up after the drag and drop operation has been completed.

A pixmap can be used to represent the data while the drag is in progress, and will move with the cursor to the drop target. This pixmap typically shows an icon that represents the MIME type of the data being transferred, but any pixmap can be set with setPixmap(). The cursor's hot spot can be given a position relative to the top-left corner of the pixmap with the setHotSpot() function. The following code positions the pixmap so that the cursor's hot spot points to the center of its bottom edge:

drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));

Note: On X11, the pixmap may not be able to keep up with the mouse movements if the hot spot causes the pixmap to be displayed directly under the cursor.

The source and target widgets can be found with source() and target(). These functions are often used to determine whether drag and drop operations started and finished at the same widget, so that special behavior can be implemented.

QDrag only deals with the drag and drop operation itself. It is up to the developer to decide when a drag operation begins, and how a QDrag object should be constructed and used. For a given widget, it is often necessary to reimplement mousePressEvent() to determine whether the user has pressed a mouse button, and reimplement mouseMoveEvent() to check whether a QDrag is required.

Methods

impl QDrag[src]

pub fn action_changed(&self) -> Signal<(DropAction,)>[src]

This signal is emitted when the action associated with the drag changes.

Returns a built-in Qt signal QDrag::actionChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted when the action associated with the drag changes.

See also targetChanged().

pub fn target_changed(&self) -> Signal<(*mut QObject,)>[src]

This signal is emitted when the target of the drag and drop operation changes, with newTarget the new target.

Returns a built-in Qt signal QDrag::targetChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted when the target of the drag and drop operation changes, with newTarget the new target.

See also target() and actionChanged().

pub unsafe fn cancel()[src]

Cancels a drag operation initiated by Qt.

Calls C++ function: static void QDrag::cancel().

C++ documentation:

Cancels a drag operation initiated by Qt.

Note: This is currently implemented on Windows and X11.

This function was introduced in Qt 5.7.

See also exec().

pub unsafe fn default_action(&self) -> DropAction[src]

Returns the default proposed drop action for this drag operation.

Calls C++ function: Qt::DropAction QDrag::defaultAction() const.

C++ documentation:

Returns the default proposed drop action for this drag operation.

See also exec() and supportedActions().

pub unsafe fn drag_cursor(&self, action: DropAction) -> CppBox<QPixmap>[src]

Returns the drag cursor for the action.

Calls C++ function: QPixmap QDrag::dragCursor(Qt::DropAction action) const.

C++ documentation:

Returns the drag cursor for the action.

This function was introduced in Qt 5.0.

See also setDragCursor().

pub unsafe fn exec_1a(
    &self,
    supported_actions: QFlags<DropAction>
) -> DropAction
[src]

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions. The default proposed action will be selected among the allowed actions in the following order: Move, Copy and Link.

Calls C++ function: Qt::DropAction QDrag::exec(QFlags<Qt::DropAction> supportedActions = …).

C++ documentation:

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions. The default proposed action will be selected among the allowed actions in the following order: Move, Copy and Link.

Note: On Linux and macOS, the drag and drop operation can take some time, but this function does not block the event loop. Other events are still delivered to the application while the operation is performed. On Windows, the Qt event loop is blocked during the operation.

This function was introduced in Qt 4.3.

See also cancel().

pub unsafe fn exec_2a(
    &self,
    supported_actions: QFlags<DropAction>,
    default_action: DropAction
) -> DropAction
[src]

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions.

Calls C++ function: Qt::DropAction QDrag::exec(QFlags<Qt::DropAction> supportedActions, Qt::DropAction defaultAction).

C++ documentation:

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions.

The defaultDropAction determines which action will be proposed when the user performs a drag without using modifier keys.

Note: On Linux and macOS, the drag and drop operation can take some time, but this function does not block the event loop. Other events are still delivered to the application while the operation is performed. On Windows, the Qt event loop is blocked during the operation. However, QDrag::exec() on Windows causes processEvents() to be called frequently to keep the GUI responsive. If any loops or operations are called while a drag operation is active, it will block the drag operation.

This function was introduced in Qt 4.3.

pub unsafe fn exec_0a(&self) -> DropAction[src]

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions. The default proposed action will be selected among the allowed actions in the following order: Move, Copy and Link.

Calls C++ function: Qt::DropAction QDrag::exec().

C++ documentation:

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in supportedActions. The default proposed action will be selected among the allowed actions in the following order: Move, Copy and Link.

Note: On Linux and macOS, the drag and drop operation can take some time, but this function does not block the event loop. Other events are still delivered to the application while the operation is performed. On Windows, the Qt event loop is blocked during the operation.

This function was introduced in Qt 4.3.

See also cancel().

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

Returns the position of the hot spot relative to the top-left corner of the cursor.

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

C++ documentation:

Returns the position of the hot spot relative to the top-left corner of the cursor.

See also setHotSpot().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QDrag::metaObject() const.

pub unsafe fn mime_data(&self) -> QPtr<QMimeData>[src]

Returns the MIME data that is encapsulated by the drag object.

Calls C++ function: QMimeData* QDrag::mimeData() const.

C++ documentation:

Returns the MIME data that is encapsulated by the drag object.

See also setMimeData().

pub unsafe fn new(drag_source: impl CastInto<Ptr<QObject>>) -> QBox<QDrag>[src]

Constructs a new drag object for the widget specified by dragSource.

Calls C++ function: [constructor] void QDrag::QDrag(QObject* dragSource).

C++ documentation:

Constructs a new drag object for the widget specified by dragSource.

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

Returns the pixmap used to represent the data in a drag and drop operation.

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

C++ documentation:

Returns the pixmap used to represent the data in a drag and drop operation.

See also setPixmap().

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QDrag::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QDrag::qt_metacast(const char* arg1).

pub unsafe fn set_drag_cursor(
    &self,
    cursor: impl CastInto<Ref<QPixmap>>,
    action: DropAction
)
[src]

Sets the drag cursor for the action. This allows you to override the default native cursors. To revert to using the native cursor for action pass in a null QPixmap as cursor.

Calls C++ function: void QDrag::setDragCursor(const QPixmap& cursor, Qt::DropAction action).

C++ documentation:

Sets the drag cursor for the action. This allows you to override the default native cursors. To revert to using the native cursor for action pass in a null QPixmap as cursor.

The action can only be CopyAction, MoveAction or LinkAction. All other values of DropAction are ignored.

See also dragCursor().

pub unsafe fn set_hot_spot(&self, hotspot: impl CastInto<Ref<QPoint>>)[src]

Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point specified by hotspot.

Calls C++ function: void QDrag::setHotSpot(const QPoint& hotspot).

C++ documentation:

Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point specified by hotspot.

Note: on X11, the pixmap may not be able to keep up with the mouse movements if the hot spot causes the pixmap to be displayed directly under the cursor.

See also hotSpot().

pub unsafe fn set_mime_data(&self, data: impl CastInto<Ptr<QMimeData>>)[src]

Sets the data to be sent to the given MIME data. Ownership of the data is transferred to the QDrag object.

Calls C++ function: void QDrag::setMimeData(QMimeData* data).

C++ documentation:

Sets the data to be sent to the given MIME data. Ownership of the data is transferred to the QDrag object.

See also mimeData().

pub unsafe fn set_pixmap(&self, arg1: impl CastInto<Ref<QPixmap>>)[src]

Sets pixmap as the pixmap used to represent the data in a drag and drop operation. You can only set a pixmap before the drag is started.

Calls C++ function: void QDrag::setPixmap(const QPixmap& arg1).

C++ documentation:

Sets pixmap as the pixmap used to represent the data in a drag and drop operation. You can only set a pixmap before the drag is started.

See also pixmap().

pub unsafe fn source(&self) -> QPtr<QObject>[src]

Returns the source of the drag object. This is the widget where the drag and drop operation originated.

Calls C++ function: QObject* QDrag::source() const.

C++ documentation:

Returns the source of the drag object. This is the widget where the drag and drop operation originated.

pub unsafe fn start_1a(
    &self,
    supported_actions: QFlags<DropAction>
) -> DropAction
[src]

Note: It is recommended to use exec() instead of this function.

Calls C++ function: Qt::DropAction QDrag::start(QFlags<Qt::DropAction> supportedActions = …).

C++ documentation:

Note: It is recommended to use exec() instead of this function.

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in request. Qt::CopyAction is always allowed.

Note: Although the drag and drop operation can take some time, this function does not block the event loop. Other events are still delivered to the application while the operation is performed.

See also exec().

pub unsafe fn start_0a(&self) -> DropAction[src]

Note: It is recommended to use exec() instead of this function.

Calls C++ function: Qt::DropAction QDrag::start().

C++ documentation:

Note: It is recommended to use exec() instead of this function.

Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. The drop actions that the user can choose from are specified in request. Qt::CopyAction is always allowed.

Note: Although the drag and drop operation can take some time, this function does not block the event loop. Other events are still delivered to the application while the operation is performed.

See also exec().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn supported_actions(&self) -> QFlags<DropAction>[src]

Returns the set of possible drop actions for this drag operation.

Calls C++ function: QFlags<Qt::DropAction> QDrag::supportedActions() const.

C++ documentation:

Returns the set of possible drop actions for this drag operation.

See also exec() and defaultAction().

pub unsafe fn target(&self) -> QPtr<QObject>[src]

Returns the target of the drag and drop operation. This is the widget where the drag object was dropped.

Calls C++ function: QObject* QDrag::target() const.

C++ documentation:

Returns the target of the drag and drop operation. This is the widget where the drag object was dropped.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QDrag::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QDrag::trUtf8(const char* s, const char* c, int n).

Trait Implementations

impl CppDeletable for QDrag[src]

unsafe fn delete(&self)[src]

Destroys the drag object.

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

C++ documentation:

Destroys the drag object.

impl Deref for QDrag[src]

type Target = QObject

The resulting type after dereferencing.

fn deref(&self) -> &QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QDrag* ptr).

impl DynamicCast<QDrag> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QDrag>[src]

Calls C++ function: QDrag* dynamic_cast<QDrag*>(QObject* ptr).

impl StaticDowncast<QDrag> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QDrag>[src]

Calls C++ function: QDrag* static_cast<QDrag*>(QObject* ptr).

impl StaticUpcast<QObject> for QDrag[src]

unsafe fn static_upcast(ptr: Ptr<QDrag>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QDrag* ptr).

Auto Trait Implementations

impl RefUnwindSafe for QDrag

impl Send for QDrag

impl Sync for QDrag

impl Unpin for QDrag

impl UnwindSafe for QDrag

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.