2

I need to stop QDrag when dragEnterEvent occurs. I want to release QDrag without releasing mouse button.

I have tried to send events to QDrag with no luck.

QMouseEvent* evt = new QMouseEvent(QEvent::MouseButtonRelease,event->pos() ,Qt::LeftButton,  Qt::LeftButton, Qt::NoModifier);
QCoreApplication::sendEvent(drag,evt);

How to achieve this?

Update: I would like to release mouse when QDragEvent occurs.

  QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseButtonRelease, event->pos (), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);

QTabBar::mouseReleaseEvent(finishMoveEvent);

qApp->sendEvent(parentWidget(),finishMoveEvent);
qApp->sendEvent(drag,finishMoveEvent);
qApp->postEvent(drag,finishMoveEvent,Qt::HighEventPriority);

I tried each of line in all possible combinations. Please help.

How to release QDrag during QDragEnterEvent.

Yash
  • 6,644
  • 4
  • 36
  • 26

1 Answers1

0

The drag itself does not receive the mouse events, widgets do. The drag filters/intercepts those events. You need to send the relevant event to the target widget, and hope that the user experience won't suffer.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I'm trying something like subime text editor tab features. You can tear of tabs and when on tabbar it automatically attach and starts moving tabs. Hope that make sense. So if QtabWidget tear off tabs when mouse over qtabbar during drag which widget will get events so that I can release qdrag event. – Yash Jun 24 '14 at 07:29
  • You might be better off reimplementing the drag/drop mechanism yourself. `QDrag` has this oddball synchronous interface (via `exec()`) and is often more trouble than it's worth. – Kuba hasn't forgotten Monica Jun 24 '14 at 17:15
  • QDrag (in Windows) exec is blocking main events also. I have checked on many forums it's a problem. – Yash Jun 27 '14 at 11:57