onamatic
11th November 2008, 13:32
Using QT4.4.3 X11, I have run into the same problem as others regarding the non-standard default drag action of QTreeView. It's documented here: QTreeView drag and drop Bug - defaults to Qt::CopyAction instead of Qt::MoveAction (http://lists.trolltech.com/qt-interest/2008-07/thread00135-0.html) but I can't find any solutions.
As far as I'm concerned, dragging an item within a tree view should default to moving the item (a la Konqueror, Windows file manager etc.); dragging from another application into the tree view should copy it.
I've spent a day trying to rectify the problem by implementing dragMoveEvent, dragEnterEvent etc. and setting the drag action explicitly:
void QAbstractItemView::dragMoveEvent ( QDragMoveEvent * event ) {
...
//force a move action unless control key is pressed
if (event->keyboardModifiers() & Qt::ControlModifier)
event->setDropAction(Qt::CopyAction);
else
event->setDropAction(Qt::MoveAction);
event->accept();
event->acceptProposedAction(); //causes cursor icon to change and target item to get highlighted
...
}
The above code works fine whilst dragging is taking place (ie: the "+" cursor copy icon disappears) but, by the time model's dropMimeData executes, the dropAction has always reverted to the default CopyAction.
Setting the treeView's dragDropMode to InternalMove is not a solution as you can not then set the DropAction to Qt::CopyAction if the user presses the control key.
QUESTION: Where can I fix the QTreeView's default drop action? Is there some kind of compatibility switch at Application level?
As far as I'm concerned, dragging an item within a tree view should default to moving the item (a la Konqueror, Windows file manager etc.); dragging from another application into the tree view should copy it.
I've spent a day trying to rectify the problem by implementing dragMoveEvent, dragEnterEvent etc. and setting the drag action explicitly:
void QAbstractItemView::dragMoveEvent ( QDragMoveEvent * event ) {
...
//force a move action unless control key is pressed
if (event->keyboardModifiers() & Qt::ControlModifier)
event->setDropAction(Qt::CopyAction);
else
event->setDropAction(Qt::MoveAction);
event->accept();
event->acceptProposedAction(); //causes cursor icon to change and target item to get highlighted
...
}
The above code works fine whilst dragging is taking place (ie: the "+" cursor copy icon disappears) but, by the time model's dropMimeData executes, the dropAction has always reverted to the default CopyAction.
Setting the treeView's dragDropMode to InternalMove is not a solution as you can not then set the DropAction to Qt::CopyAction if the user presses the control key.
QUESTION: Where can I fix the QTreeView's default drop action? Is there some kind of compatibility switch at Application level?