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
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);
}
}
void QTreeWidgetDragDrop::mousePressEvent(QMouseEvent *event)
{
// Get current selection
QTreeWidgetItem *selectedItem = currentItem();
// If the selected Item exists
if (selectedItem)
{
// Create data
QMimeData *mimeData = new QMimeData();
mimeData->setText("hello");
// Create drag
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
QTreeWidget::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
and this is the code I have in my custom QTableWidget
{
qDebug() << "dragEnterEvent text: " << event->mimeData()->text();
// Allways accept at first
event->acceptProposedAction();
}
void QTableWidgetDragDrop::dragEnterEvent(QDragEnterEvent *event)
{
qDebug() << "dragEnterEvent text: " << event->mimeData()->text();
// Allways accept at first
event->acceptProposedAction();
QTableWidget::dragEnterEvent(event);
}
To copy to clipboard, switch view to plain text mode
And this is the function to catch the drop event
void QTableWidgetDragDrop
::dropEvent(QDropEvent *event
) {
qDebug() << "enter in dropEvent";
}
void QTableWidgetDragDrop::dropEvent(QDropEvent *event)
{
qDebug() << "enter in dropEvent";
}
To copy to clipboard, switch view to plain text mode
I cannot drop my item because I have the forbiden cursor, I never see the sentence "enter in dropEvent" but I have in output
dragEnterEvent text: "hello"
In addition, I have put in my QTableWidget constructor:
this->setAcceptDrops(true);
this->setAcceptDrops(true);
To copy to clipboard, switch view to plain text mode
Any idea ...?
Bookmarks