|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QDrag
public class QDrag
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. Care must be taken to ensure that the pixmap is not too large. 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.
Icons Example
,
Text Example
,
Site Example
,
Fridge Magnets ExampleNested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary | |
---|---|
QSignalEmitter.Signal1<Qt.DropAction> |
actionChanged
This signal is emitted when the action associated with the drag changes. |
QSignalEmitter.Signal1<QWidget> |
targetChanged
This signal is emitted when the target of the drag and drop operation changes, with newTarget the new target. |
Constructor Summary | |
---|---|
QDrag(QWidget dragSource)
Constructs a new drag object for the widget specified by dragSource. |
Method Summary | |
---|---|
Qt.DropAction |
exec()
Equivalent to exec(Qt::MoveAction). |
Qt.DropAction |
exec(Qt.DropAction... supportedActions)
Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. |
Qt.DropAction |
exec(Qt.DropActions supportedActions)
Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. |
Qt.DropAction |
exec(Qt.DropActions supportedActions,
Qt.DropAction defaultAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it is completed. |
static QDrag |
fromNativePointer(QNativePointer nativePointer)
This function returns the QDrag instance pointed to by nativePointer |
QPoint |
hotSpot()
Returns the position of the hot spot relative to the top-left corner of the cursor. |
QMimeData |
mimeData()
Returns the MIME data that is encapsulated by the drag object. |
QPixmap |
pixmap()
Returns the pixmap used to represent the data in a drag and drop operation. |
void |
setDragCursor(QPixmap cursor,
Qt.DropAction action)
Sets the drag cursor for the action. |
void |
setHotSpot(QPoint hotspot)
Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point specified by hotspot. |
void |
setMimeData(QMimeData data)
Sets the data to be sent to the given MIME data. |
void |
setPixmap(QPixmap arg__1)
Sets arg__1 as the pixmap used to represent the data in a drag and drop operation. |
QWidget |
source()
Returns the source of the drag object. |
QWidget |
target()
Returns the target of the drag and drop operation. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
disconnect, disconnect, signalSender |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal1<Qt.DropAction> actionChanged
This signal is emitted when the action associated with the drag changes.
public final QSignalEmitter.Signal1<QWidget> targetChanged
This signal is emitted when the target of the drag and drop operation changes, with newTarget the new target.
Constructor Detail |
---|
public QDrag(QWidget dragSource)
Constructs a new drag object for the widget specified by dragSource.
Method Detail |
---|
public final Qt.DropAction exec(Qt.DropAction... supportedActions)
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 Mac OS X, 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 while during the operation.
public final Qt.DropAction exec()
Equivalent to exec(Qt::MoveAction).
public final Qt.DropAction exec(Qt.DropActions supportedActions)
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 Mac OS X, 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 while during the operation.
public final Qt.DropAction exec(Qt.DropActions supportedActions, Qt.DropAction defaultAction)
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 defaultAction determines which action will be proposed when the user performs a drag without using modifier keys.
Note: Although the drag and drop operation is blocking, the function does not block the event loop. Other events are still delivered to the application while the operation is performed.
public final QPoint hotSpot()
Returns the position of the hot spot relative to the top-left corner of the cursor.
public final QMimeData mimeData()
Returns the MIME data that is encapsulated by the drag object.
public final QPixmap pixmap()
Returns the pixmap used to represent the data in a drag and drop operation.
public final void setDragCursor(QPixmap cursor, Qt.DropAction action)
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.
public final void setHotSpot(QPoint hotspot)
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.
public final void setMimeData(QMimeData data)
Sets the data to be sent to the given MIME data. Ownership of the data is transferred to the QDrag object.
public final void setPixmap(QPixmap arg__1)
Sets arg__1 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.
public final QWidget source()
Returns the source of the drag object. This is the widget where the drag and drop operation originated.
public final QWidget target()
Returns the target of the drag and drop operation. This is the widget where the drag object was dropped.
public static QDrag fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |