Drag and drop QTreeWidgetItem to QTableWidget
Hi
I'm trying to drag a QTreeWidgetItem from a custom QTreeWidget into a QTableWidget.
My problem is that i always have the forbiden cursor when I'm on the QTableWidget, and I never received the "drop" event!
This is the code in my custom QTreeWidget
Code:
void QTreeWidgetDragDrop
::mousePressEvent(QMouseEvent *event
) {
// Get current selection
// If the selected Item exists
if (selectedItem)
{
// Create data
mimeData->setText("hello");
// Create drag
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
}
and this is the code I have in my custom QTableWidget
Code:
{
qDebug() << "dragEnterEvent text: " << event->mimeData()->text();
// Allways accept at first
event->acceptProposedAction();
}
And this is the function to catch the drop event
Code:
void QTableWidgetDragDrop
::dropEvent(QDropEvent *event
) {
qDebug() << "enter in dropEvent";
}
I cannot drop my item because I have the forbiden cursor, I never see the sentence "enter in dropEvent" but I have in output
Quote:
dragEnterEvent text: "hello"
In addition, I have put in my QTableWidget constructor:
Code:
this->setAcceptDrops(true);
Any idea ...?
Re: Drag and drop QTreeWidgetItem to QTableWidget
try to reimplement
Code:
QTableWidgetDragDrop::dragMoveEvent(...)
and accept event here too
Re: Drag and drop QTreeWidgetItem to QTableWidget
can you try it in debug mode and check all events?
Re: Drag and drop QTreeWidgetItem to QTableWidget
I have already implemented dragMoveEvent, but I don't receive the event too...
I'll try to check events in debug mode, I have to learn how the debug mode works.
Re: Drag and drop QTreeWidgetItem to QTableWidget
The call of "QAbstractItemView::dragEnterEvent" (in the mother class) contains
Code:
if (d_func()->canDecode(event)) {
event->accept();
setState(DraggingState);
} else {
event->ignore();
}
But, I saw in debug that it always goes in "event->ignore();", I have to work on that point ...
=> http://doc.trolltech.com/4.2/model-v...bclassing.html part "Drag and Drop Support and MIME Type Handling"
Re: Drag and drop QTreeWidgetItem to QTableWidget
I figured out!
My problem was what I found: I didn't set a model, and I didn't put my data into the default model!
So I put my data into the default model, and now I can see all my events!
My next step is to create my own model!
(You can put this thread as resolved ;) )
Thanks for your help ;)
Code:
void QTreeWidgetDragDrop
::mousePressEvent(QMouseEvent *event
) {
// Get current selection
// If the selected Item exists
if (selectedItem)
{
dataStream << "Hello";
mimeData->setData("application/x-qabstractitemmodeldatalist", itemData);
// Create drag
drag->setMimeData(mimeData);
qDebug() << "mousePressEvent before exec";
drag->exec(Qt::CopyAction);
qDebug() << "mousePressEvent after exec";
}
}