Hi,
sorry it took so long. Here is my (very simple) tree widget
----------------------------------------------------------------------------
#include "myQTTreeWidget.h"
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QList>
myQTTreeWidget
::myQTTreeWidget(QWidget* parent
) {
setAcceptDrops(true);
setDragEnabled(true);
setHeaderLabel("Name");
setColumnCount(1);
item1->setText(0,"hello");
item2->setText(0,"world!");
item3->setText(0,"whats");
item4->setText(0,"up?");
}
myQTTreeWidget::~myQTTreeWidget()
{
}
{
e->accept();
}
{
e->accept();
}
QMimeData *myQTTreeWidget
::mimeData(const QList<QTreeWidgetItem
*> items
) const {
}
bool myQTTreeWidget
::dropMimeData ( QTreeWidgetItem * newParentPtr,
int index,
const QMimeData * data, Qt
::DropAction action
) {
return true;
}
Qt::DropActions myQTTreeWidget::supportedDropActions () const
{
return Qt::CopyAction|Qt::MoveAction;
}
#include "myQTTreeWidget.h"
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QList>
myQTTreeWidget::myQTTreeWidget(QWidget* parent)
: QTreeWidget(parent)
{
setAcceptDrops(true);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragDrop);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setEditTriggers(QAbstractItemView::SelectedClicked);
setHeaderLabel("Name");
setColumnCount(1);
QTreeWidgetItem *item1 = new QTreeWidgetItem(this);
QTreeWidgetItem *item2 = new QTreeWidgetItem(this);
QTreeWidgetItem *item3 = new QTreeWidgetItem(this);
QTreeWidgetItem *item4 = new QTreeWidgetItem(this);
item1->setText(0,"hello");
item2->setText(0,"world!");
item3->setText(0,"whats");
item4->setText(0,"up?");
}
myQTTreeWidget::~myQTTreeWidget()
{
}
void myQTTreeWidget::dragEnterEvent(QDragEnterEvent *e)
{
e->accept();
}
void myQTTreeWidget::dragMoveEvent(QDragMoveEvent *e)
{
e->accept();
}
QMimeData *myQTTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const
{
return new QMimeData;
}
bool myQTTreeWidget::dropMimeData ( QTreeWidgetItem * newParentPtr, int index, const QMimeData * data, Qt::DropAction action )
{
return true;
}
Qt::DropActions myQTTreeWidget::supportedDropActions () const
{
return Qt::CopyAction|Qt::MoveAction;
}
To copy to clipboard, switch view to plain text mode
-----------------------------------------------------------------------------
If you want to reproduce the behaviour, you can place a breakpoint into dropMimeData (or some kind of fprintf(...) output ). You will see that this function is called if you try to drag & drop one of the items (without pressing Shift!). But it is not called if you press the Shift key while you're dragging/dropping the item. If you try to drag&drop an item without pressing Shift - nothing happens after dropping the item (that's ok, the drop function is empty). If you drag&drop an item while the Shift key is pressed, then the item is moved after dropping it (wherever this behaviour is implemented).
Maybe there is something totally wrong with my code. Maybe I made something very stupid? Any suggestion is very welcome.
Thanks, take care
Bookmarks