No drag target set ?
-
MainWindow(0x550db4f6b0, name="MainWindow") : No drag target set.Sometimes it gives this error when I drop a widget in a custom area set. I've looked on the net but couldn't find any documentation that directly explains this error.
Why am I getting this error? -
Hi,
How did you implement drag and drop ?
-
Hello, of course, if we briefly summarize the code;
This is how I initiate a drag when the widget is clicked.if(widget == Q_NULLPTR) return; QByteArray byteArray(reinterpret_cast<char*>(&widget),sizeof(QWidget*)); QDrag *drag = new QDrag(this); QMimeData * mimeData = new QMimeData; mimeData->setData("Label",byteArray); drag->setMimeData(mimeData); QPoint globalPos = mapToGlobal(pos); QPoint p = widget->mapFromGlobal(globalPos); drag->setHotSpot(p); drag->setPixmap(widget->grab()); drag->exec(Qt::CopyAction | Qt::MoveAction);then I use dragenterevent and dropevent functions in the widget I will carry.
DropEvent:if(event->mimeData()->hasFormat("Label") ) // in listwidget class { event->acceptProposedAction(); QByteArray byteArray = event->mimeData()->data("Label"); QWidget * widget = *reinterpret_cast<QWidget**>(byteArray.data()); KrnLabel * new_label = qobject_cast<KrnLabel *>(widget); QListWidgetItem *item = new QListWidgetItem(); QSize size = QSize(new_label->sizeHint().width()+15,new_label->sizeHint().height()); item->setSizeHint(size); addItem(item); setItemWidget(item,new_label ); } else event->ignore(); }It doesn't always give this error. It only happens at certain times. For example, when I drag 7-8 widgets, I only get this error on one of them.
Why am I getting this error randomly? -
The implementation itself does not look wrong although I wouldn't move pointers to widget pointers around.
-
I have a doubt that this is a bug.
Can you provide a minimal compilable example that reliably shows this message ?
By the way, which version of Qt are you using ?
On which platform ?