Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QDrag Class Reference

Inheritance diagram for QDrag:

QObject

List of all members.


Detailed Description

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:

snippets/dragging/mainwindow.cpp mousePressEvent QDrag setMimeData

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:

snippets/separations/finalwidget.cpp setHotSpot ;

{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 {QWidget::mousePressEvent()}{mousePressEvent()} to determine whether the user has pressed a mouse button, and reimplement {QWidget::mouseMoveEvent()}{mouseMoveEvent()} to check whether a QDrag is required.

See also:
{Drag and Drop}, QClipboard, QMimeData, QWindowsMime, QMacPasteboardMime, {Draggable Icons Example}, {Draggable Text Example}, {Drop Site Example}, {Fridge Magnets Example}

Definition at line 61 of file qdrag.h.


Public Slots

void deleteLater ()

Signals

void actionChanged (Qt::DropAction action)
void destroyed (QObject *=0)
void targetChanged (QWidget *newTarget)

Public Member Functions

bool blockSignals (bool b)
const QObjectListchildren () const
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
bool disconnect (const QObject *receiver, const char *member=0)
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
void dumpObjectInfo ()
void dumpObjectTree ()
QList< QByteArraydynamicPropertyNames () const
virtual bool event (QEvent *)
virtual bool eventFilter (QObject *, QEvent *)
Qt::DropAction exec (Qt::DropActions supportedActions, Qt::DropAction defaultAction)
Qt::DropAction exec (Qt::DropActions supportedActions=Qt::MoveAction)
template<typename T>
findChild (const QString &name=QString()) const
template<typename T>
QList< T > findChildren (const QRegExp &re) const
template<typename T>
QList< T > findChildren (const QString &name=QString()) const
QPoint hotSpot () const
bool inherits (const char *classname) const
void installEventFilter (QObject *)
bool isWidgetType () const
void killTimer (int id)
QMimeDatamimeData () const
void moveToThread (QThread *thread)
QString objectName () const
QObjectparent () const
QPixmap pixmap () const
QVariant property (const char *name) const
 QDrag (QWidget *dragSource)
void removeEventFilter (QObject *)
void setDragCursor (const QPixmap &cursor, Qt::DropAction action)
void setHotSpot (const QPoint &hotspot)
void setMimeData (QMimeData *data)
void setObjectName (const QString &name)
void setParent (QObject *)
void setPixmap (const QPixmap &)
bool setProperty (const char *name, const QVariant &value)
void setUserData (uint id, QObjectUserData *data)
bool signalsBlocked () const
QWidgetsource () const
Qt::DropAction start (Qt::DropActions supportedActions=Qt::CopyAction)
int startTimer (int interval)
QWidgettarget () const
QThreadthread () const
QObjectUserData * userData (uint id) const
 ~QDrag ()

Static Public Member Functions

static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
static uint registerUserData ()

Protected Member Functions

virtual void childEvent (QChildEvent *)
virtual void connectNotify (const char *signal)
virtual void customEvent (QEvent *)
virtual void disconnectNotify (const char *signal)
int receivers (const char *signal) const
QObjectsender () const
virtual void timerEvent (QTimerEvent *)

Protected Attributes

QObjectData * d_ptr

Static Protected Attributes

static const QMetaObject staticQtMetaObject

Properties

QString objectName
 the name of this object

Friends

class QApplication
class QApplicationPrivate
class QCoreApplication
class QCoreApplicationPrivate
class QDragManager
struct QMetaObject
class QThreadData
class QWidget

Related Functions

(Note that these are not member functions.)

qFindChild (const QObject *obj, const QString &name=QString(), T dummy=0)
qFindChild (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QString &name=QString(), T dummy=0)
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
QList< T > qFindChildren (const QObject *obj, const QString &name)
T * qobject_cast (QObject *object)
 QObjectList
void * qt_find_obj_child (QObject *parent, const char *type, const QString &name)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index