Drop not working correctly
Hello! Im dragging from a QTreeWidget to QGraphicsScene. And drop action doesnt occur.
This code for drag:
Code:
{
if (event->button() == Qt::LeftButton)
dragStartPosition = event->pos();
}
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event
->pos
() - dragStartPosition
).
manhattanLength() <
QApplication::startDragDistance()) return;
if(this
->currentItem
()->text
(0) == QString::fromLocal8Bit("Text")) {
lb->setMaximumSize(100,20);
lb->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
drag
->setPixmap
(QPixmap::grabWidget(lb
));
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec();
}
And this is for drop:
Code:
{
setAcceptDrops(true);
}
{
cout << "drag entered" << endl;
e->acceptProposedAction();
}
{
cout << "dropped" << endl;
e->acceptProposedAction();
}
dragEnterEvent works correctly (at least cout in it). But dropEvent doesnt. And drop accepted symbol (+) isnt shown over pixmap im dragging.
Help would be appreciated. Thanks in advance.
Re: Drop not working correctly
I'm no expert and I've only used QTreeViews, not QTreeWidgets directly. It struck me that you don't set up any MimeFormats (or data) so the view won't know what's being dropped on it:
Code:
...
//without the following line, my drag/drops with a QTreeView went badly wrong
mimeData
->setData
(("application/x-something",
QByteArray());
//replace x-something and QByteArray() if necessary drag->setMimeData(mimeData);
...
Just my ignorant thoughts - sorry if they're irrelevant!
Re: Drop not working correctly
Unfortunately, its not the point (. QMimeData instance should be specified fo QDrag to work, but i believe its not important is there any real information in this instance.
Besides im passing some real info in my programm. I just cut those blocks from example code for the sake of simplicity.
The problem is not that Drop drops something wrong, but that it doesnt even occur, like my accepting widget acceptDrops is FALSE.