Drag and Drop (Simple)This provides a very simple example of Qt's drag and drop functionality. For a more complete example see the Drag and Drop example.
Header file:
/**************************************************************************** ** $Id$ ** ** Copyright (C) 1992-2001 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include <qapplication.h> #include <qcursor.h> #include <qsplitter.h> #include <qlistbox.h> #include <qiconview.h> #include <qpixmap.h> class QDragEnterEvent; class QDragDropEvent; class DDListBox : public QListBox { Q_OBJECT public: DDListBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); // Low-level drag and drop void dragEnterEvent( QDragEnterEvent *evt ); void dropEvent( QDropEvent *evt ); void mousePressEvent( QMouseEvent *evt ); void mouseMoveEvent( QMouseEvent * ); private: int dragging; }; class DDIconViewItem : public QIconViewItem { public: DDIconViewItem( QIconView *parent, const QString& text, const QPixmap& icon ) : QIconViewItem( parent, text, icon ) {} DDIconViewItem( QIconView *parent, const QString &text ) : QIconViewItem( parent, text ) {} // High-level drag and drop bool acceptDrop( const QMimeSource *mime ) const; void dropped( QDropEvent *evt, const QValueList<QIconDragItem>& ); }; class DDIconView : public QIconView { Q_OBJECT public: DDIconView( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : QIconView( parent, name, f ) {} // High-level drag and drop QDragObject *dragObject(); public slots: void slotNewItem( QDropEvent *evt, const QValueList<QIconDragItem>& list ); };
Implementation:
/****************************************************************************
** $Id$
**
** Copyright (C) 1992-2001 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "main.h"
const char* red_icon[]={
"16 16 2 1",
"r c red",
". c None",
"................",
"................",
"..rrrrrrrrrrrr..",
"..rrrrrrrrrrrr..",
"..rrrrrrrrrrrr..",
"..rrr......rrr..",
"..rrr......rrr..",
"..rrr......rrr..",
"..rrr......rrr..",
"..rrr......rrr..",
"..rrr......rrr..",
"..rrrrrrrrrrrr..",
"..rrrrrrrrrrrr..",
"..rrrrrrrrrrrr..",
"................",
"................"};
const char* blue_icon[]={
"16 16 2 1",
"b c blue",
". c None",
"................",
"................",
"..bbbbbbbbbbbb..",
"..bbbbbbbbbbbb..",
"..bbbbbbbbbbbb..",
"..bbb......bbb..",
"..bbb......bbb..",
"..bbb......bbb..",
"..bbb......bbb..",
"..bbb......bbb..",
"..bbb......bbb..",
"..bbbbbbbbbbbb..",
"..bbbbbbbbbbbb..",
"..bbbbbbbbbbbb..",
"................",
"................"};
const char* green_icon[]={
"16 16 2 1",
"g c green",
". c None",
"................",
"................",
"..gggggggggggg..",
"..gggggggggggg..",
"..gggggggggggg..",
"..ggg......ggg..",
"..ggg......ggg..",
"..ggg......ggg..",
"..ggg......ggg..",
"..ggg......ggg..",
"..ggg......ggg..",
"..gggggggggggg..",
"..gggggggggggg..",
"..gggggggggggg..",
"................",
"................"};
// ListBox -- low level drag and drop
See also Examples. |
| 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 3.2 | |
| 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 ! | ||
Copyright © 2000-2012 - www.developpez.com