change "+" symbol to other symbol when dragging an item from listview to treeview .
-
You should handle these events on the widget you want to handle the drop (the listview), not on main window. That's one.
Second - why are you creating new QDrag objects in every move event? There are gonna be tons of them and you are not releasing any of them! There is already a drag in progress. Don't create new ones.
Don't change the cursor in move event. Set a cursor for drag object where you create it (I'm guessing in mouse press of the treeview?) and don't touch again. It will change when you accept or not a move event.
-
You should handle these events on the widget you want to handle the drop (the listview), not on main window. That's one.
Second - why are you creating new QDrag objects in every move event? There are gonna be tons of them and you are not releasing any of them! There is already a drag in progress. Don't create new ones.
Don't change the cursor in move event. Set a cursor for drag object where you create it (I'm guessing in mouse press of the treeview?) and don't touch again. It will change when you accept or not a move event.
@Chris-Kawa
How to create the events on widgets? like show below??void QListView::dragMoveEvent(QDragMoveEvent *event) { // }
I do not want to to change the cursor on entire drag event from listview to treeview. I just want to change the cursor when there is empty space as shown here and not when like this.
-
Subclass QListView and override
dragEnterEvent
,dragMoveEvent
anddropEvent
.In
dragEnterEvent
check the mime type in parameter andevent->acceptProposedAction
if it's something you can drop onto the list.
IndragMoveEvent
check cursor position andevent->acceptProposedAction()
orevent->ignore()
, depending on the cursor position.
IndropEvent
get the event data and physically insert item into list.You don't really need to set any cursors. It will change automatically when you accept or ignore the event in the
dragMoveEvent
. -
Subclass QListView and override
dragEnterEvent
,dragMoveEvent
anddropEvent
.In
dragEnterEvent
check the mime type in parameter andevent->acceptProposedAction
if it's something you can drop onto the list.
IndragMoveEvent
check cursor position andevent->acceptProposedAction()
orevent->ignore()
, depending on the cursor position.
IndropEvent
get the event data and physically insert item into list.You don't really need to set any cursors. It will change automatically when you accept or ignore the event in the
dragMoveEvent
.@Chris-Kawa
I tried this way. Is this the way to do??void QlistView::dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE { QPoint cursorPosition = event->pos() ; QModelIndex index = BusAnalyzerWindow::ui->listView_Messages->indexAt(cursorPosition); if(index.isValid()) event->acceptProposedAction(); } void QListView::dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE { if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) event->acceptProposedAction(); } void QListView::dropEvent(QDropEvent *event) { event->setDropAction(Qt::MoveAction); event->accept(); }
But
dragEnterEvent
is not member of Qlistview So it failed. -
You can't just overwrite QListView methods. As I said - subclass QListView and override the methods there.
Aside from that you should also
event->ignore()
in adragMoveEvent
else clause. -
You can't just overwrite QListView methods. As I said - subclass QListView and override the methods there.
Aside from that you should also
event->ignore()
in adragMoveEvent
else clause.@Chris-Kawa
I dono how to subclass QListView and override . -
-
@Chris-Kawa
I will look into it. -
@Chris-Kawa
I will look into it.@Chris-Kawa
I tried these ways . But none of the two is working.myWindow::myWindow(QWidget *parent,QMdiArea *mdiParent): QWidget(parent), QListView(parent) ui(new Ui::myWindow) { ui->setupUi(this); // }
nor this as suggested here .
class myWindow: public QWidget { Q_OBJECT public: explicit myWindow(QWidget *parent = 0, QMdiArea *mdiParent=0) : QListView (paren,mdiParent ){} ......
Is there any document giving info about subclass?
-
@Chris-Kawa
I tried these ways . But none of the two is working.myWindow::myWindow(QWidget *parent,QMdiArea *mdiParent): QWidget(parent), QListView(parent) ui(new Ui::myWindow) { ui->setupUi(this); // }
nor this as suggested here .
class myWindow: public QWidget { Q_OBJECT public: explicit myWindow(QWidget *parent = 0, QMdiArea *mdiParent=0) : QListView (paren,mdiParent ){} ......
Is there any document giving info about subclass?
I used
dragMoveEvent
to restrict the+
symbol.void dragMoveEvent(QDragMoveEvent *event) { QPoint cursorPosition = event->pos() ; QModelIndex index = indexAt(cursorPosition); if(index.parent().isValid()) { event->acceptProposedAction(); } else event->ignore(); }