| ID | ... | Creation date | 15 June 2009 |
| Platform | S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition | Tested on devices | S60 Emulator |
| Category | Qt for S60 | Subcategory | Application |
| Keywords (APIs, classes, methods, functions): QListWidget,QHBoxLayout |
Qt's drag and drop infrastructure is fully supported by the model/view framework. Items in lists, tables, and trees can be dragged within the views, and data can be imported and exported as MIME-encoded data.
This Example show,how to perform drag and drop operation in Qt.
This exmaple makes the use of following class
QListWidget-Use to list out widget
list->setDragDropMode(QAbstractItemView::InternalMove);
here in the above function we can move the item or we can manually sor the item in one list..
If its value is true, the selected data will overwrite the existing item data when dropped, while moving the data will clear the item.
If its value is false, the selected data will be inserted as a new item when the data is dropped. When the data is moved, the item is removed as well.
list->setDragDropOverwriteMode ( 1 );
#include <QtGui/QWidget>
#include<QListWidget>
#include<QHBoxLayout>
class drag : public QWidget
{
Q_OBJECT
public:
drag(QWidget *parent = 0);
~drag();
private:
QListWidget *list;
QListWidget *list1;
QHBoxLayout *lay;
};
#endif // DRAG_H
#include "drag.h"
#include<QAbstractItemView>
drag::drag(QWidget *parent)
: QWidget(parent)
{
list=new QListWidget(this);
list->resize(0,0);
list1=new QListWidget(this);
lay=new QHBoxLayout(this);
list->addItem("Nokia"); //Adding item to list
list->addItem("Samsung");
list->addItem("Motorola");
list1->addItem("Nokia 6630");
list1->addItem("5800 Xpress Music");
list1->addItem("N96");
list->setSelectionMode(QAbstractItemView::SingleSelection); // single item can be draged or droped
list->setDragEnabled(true);
list->setDragDropMode(QAbstractItemView::InternalMove);
list->viewport()->setAcceptDrops(true);
list->setDropIndicatorShown(true);
list1->setSelectionMode(QAbstractItemView::SingleSelection);
list1->setDragEnabled(true);
list1->viewport()->setAcceptDrops(true);
list1->setDropIndicatorShown(true);
lay->addWidget(list);
lay->addWidget(list1);
setLayout(lay);
list->setStyleSheet("* { background-color:rgb(150,147,88);color:rgb(255,255,255); padding: 7px}}");
list1->setStyleSheet("* { background-color:rgb(150,140,70);color:rgb(255,255,255); padding: 7px}}");
resize(200,200);
}
drag::~drag()
{
// No need to delete any object that got a parent that is properly deleted.
}
No related wiki articles found