CopperSpice API
1.9.2
|
The QDrag class provides support for MIME-based drag and drop data transfer. More...
Public Signals | |
void | actionChanged (Qt::DropAction action) |
void | targetChanged (QObject *newTarget) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Methods | |
QDrag (QObject *dragSource) | |
~QDrag () | |
Qt::DropAction | defaultAction () const |
QPixmap | dragCursor (Qt::DropAction action) const |
Qt::DropAction | exec (Qt::DropActions supportedActions, Qt::DropAction defaultAction) |
Qt::DropAction | exec (Qt::DropActions supportedActions=Qt::MoveAction) |
QPoint | hotSpot () const |
QMimeData * | mimeData () const |
QPixmap | pixmap () const |
void | setDragCursor (const QPixmap &cursor, Qt::DropAction action) |
void | setHotSpot (const QPoint &hotspot) |
void | setMimeData (QMimeData *data) |
void | setPixmap (const QPixmap &pixmap) |
QObject * | source () const |
Qt::DropAction | start (Qt::DropActions supportedActions=Qt::CopyAction) |
Qt::DropActions | supportedActions () const |
QObject * | target () const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
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 CopperSpice 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:
Calling setMimeData() will assign ownership of the QMimeData object to the QDrag object. The QDrag must be constructed on the heap with a parent QWidget to ensure that CopperSpice 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:
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.
|
explicit |
Constructs a new drag object for the widget specified by dragSource.
QDrag::~QDrag | ( | ) |
Destroys the drag object.
|
signal |
This signal is emitted when the action associated with the drag changes.
Qt::DropAction QDrag::defaultAction | ( | ) | const |
Returns the default proposed drop action for this drag operation.
QPixmap QDrag::dragCursor | ( | Qt::DropAction | action | ) | const |
Returns the drag cursor for the action.
Qt::DropAction QDrag::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.
Qt::DropAction QDrag::exec | ( | Qt::DropActions | supportedActions = Qt::MoveAction | ) |
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.
QPoint QDrag::hotSpot | ( | ) | const |
Returns the position of the hot spot relative to the top-left corner of the cursor.
QMimeData * QDrag::mimeData | ( | ) | const |
Returns the MIME data that is encapsulated by the drag object.
QPixmap QDrag::pixmap | ( | ) | const |
Returns the pixmap used to represent the data in a drag and drop operation.
void QDrag::setDragCursor | ( | const 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.
void QDrag::setHotSpot | ( | const 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 QDrag::setMimeData | ( | QMimeData * | data | ) |
Sets the data to be sent to the given MIME data. Ownership of the data is transferred to the QDrag object.
void QDrag::setPixmap | ( | const QPixmap & | pixmap | ) |
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.
QObject * QDrag::source | ( | ) | const |
Returns the source of the drag object. This is the widget where the drag and drop operation originated.
|
deprecated |
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. Qt::CopyAction is always allowed.
Qt::DropActions QDrag::supportedActions | ( | ) | const |
Returns the set of possible drop actions for this drag operation.
QObject * QDrag::target | ( | ) | const |
Returns the target of the drag and drop operation. This is the widget where the drag object was dropped.
|
signal |
This signal is emitted when the target of the drag and drop operation changes, with newTarget the new target.