Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QDrag Class Reference
[QtGui module]

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

#include <QDrag>

Inherits QObject.

Public Functions

  • 28 public functions inherited from QObject

Signals

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 4 static public members inherited from QObject
  • 7 protected functions inherited from QObject

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:

            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()));

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.

See also Drag and Drop, QClipboard, and QMimeData.


Member Function Documentation

QDrag::QDrag ( QWidget * dragSource )

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

QDrag::~QDrag ()

Destroys the drag object.

void QDrag::actionChanged ( Qt::DropAction action )   [signal]

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

See also targetChanged().

QPoint QDrag::hotSpot () const

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

See also setHotSpot().

QMimeData * QDrag::mimeData () const

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

See also setMimeData().

QPixmap QDrag::pixmap () const

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

See also setPixmap().

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.

See also 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.

See also mimeData().

void QDrag::setPixmap ( const QPixmap & pixmap )

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

See also pixmap().

QWidget * QDrag::source () const

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

Qt::DropAction QDrag::start ( Qt::DropActions request = Qt::CopyAction )

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.

QWidget * QDrag::target () const

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

void QDrag::targetChanged ( QWidget * newTarget )   [signal]

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

See also target() and actionChanged().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 9
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.1
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web