Ending QDrag prematurely.
-
I want my application to accept the drag as a drop immediately as soon as the drag has entered. Is this possible?
I have tried sending a QDropEvent to my widget on its dragEnterEvent() method, but the QDrag::exec() does not return anything (it doesn't count as a drop from the QDrag at all, I still see my pixmap and modified cursor).
-
Did you use QGraphicsItem?
-
I tried and it didn't work. I tried with both sending the event to the widget and to the application's event processor with no avail.
@
QMouseEvent mouseEvent(QEvent::MouseButtonRelease, event->pos(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
QCoreApplication::postEvent(static_cast<QObject*>(this), &mouseEvent, Qt::NormalEventPriority);@Anyone have any more suggestions?
-
It does realize when the mouse enters. The problem is forcing it to stop.
@QDrag drag = new QDrag(this);
=QMimeData mimeData = new QMimeData();
=mimeData->setData("tab-detach", QByteArray::number(clickIndex));
drag->setMimeData(mimeData);switch(drag->exec(Qt::MoveAction | Qt::CopyAction))
{
case Qt::MoveAction:
qDebug() << "Accepted";
break;
default:
qDebug() << "Ignored";
tabWidget->insertTab(position, dragWidget, dragText);
tabWidget->setCurrentIndex(position);
}@@
void ResourceTabBar::dragEnterEvent(QDragEnterEvent *event)
{
QByteArray a = event->mimeData()->data("tab-detach");
if (!a.isEmpty() && dragTab != nullptr)
{
qDebug() << dragTab;
// This is where I've been trying to stop it.
}
QTabBar::dragEnterEvent(event);
}@I can see the drag entered. I tried posting the code I posted previously to the comment in the latter code. I can make a dropEvent execute, but the drag->exec() does not end if I do.
-
What you are doing in case of something other than Qt::MoveAction is just reverting changes done before, I suppose?
Are you actually implementing the dropEvent() to have full control over it?
What happens if you call the base classes dropEvent() within the dragEnterEvent()? Something like the following:
@void QWidget::dragEnterEvent(QDragEnterEvent *event)
{
QWidget::dropEvent(event);//no calling of the "proper" base class implementation
}
@If nothing works, I would try to just call "delete drag" once it is not needed anymore (reparent it first). I don't know if that causes a crash, or if the drag finishes in a clean manner.
-
I handle the ignore, if necessary. The dropEvent simply accepts.
The code you provided did not do anything. Your idea does not work either. I tried to delete the drag on the qDrag::targetChanged signal and it does nothing at all.
I have tried checking the repository for the source and I cannot figure out how dragging works internally. What I do know is that on Windows (which is what platform I'm currently on), any events that I pass to QCoreApplication will be blocked until the QDrag exits. This is why I can't just post a drop event.
-