PDA

View Full Version : Cannot cancel Drag when Dialog exec() is fired [Windows]



LepaBrena
30th April 2020, 09:04
In Windows when I drag item and dialog exec() is called I cannot do anything. I cannot cancel drag neither click on dialog buttons.
QDrag::cancel() is called before dialog exec() and still nothing. Also I tried to call processEvents() after cancel, with our without time delay, but it still do nothing.


int myDialog::exec()
{
getActiveDrag()->cancel();

QTime dieTime= QTime::currentTime().addSecs(1);

while (QTime::currentTime() < dieTime)
{
QCoreApplication::processEvents(QEventLoop::AllEve nts, 100);
}

return QDialog::exec();
}

I've found that similar problem is reported to Qt, but maybe someone has some workaround.
https://bugreports.qt.io/browse/QTBUG-58661

d_stranz
30th April 2020, 23:24
getActiveDrag()->cancel();

QDrag::cancel() is a static member function of QDrag. You do not call it through a pointer to a QDrag instance.



QTime dieTime= QTime::currentTime().addSecs(1);

while (QTime::currentTime() < dieTime)
{
QCoreApplication:: processEvents(QEventLoop:: AllEvents, 100);
}


And what is this bizarre piece of code? Just call QCoreApplication::processEvents(). That will empty the event queue. You don't need to spin in a loop.

In any case, QDrag::exec() blocks the Windows event loop, but also internally calls processEvents() to keep the GUI active so this extra call to processEvents() is unnecessary.

LepaBrena
14th May 2020, 11:18
My mistake. I've missed "Static Public Members" for QDrag::cancel().

Anyway, calling QDialog::exec(), with or without processEvents() will not cancel drag. Also, calling QDrag::cancel() before calling QDialog::exec() will not cancel drag neither.

The result is that I have both, a message box and a drag, displayed at the same time.

d_stranz
14th May 2020, 17:35
I think QDrag::cancel() works only on drag operations created internally by Qt, not on drag operations started in your own application code. An example of this might be reordering the rows / columns in a table widget when a "movable" property is set.

If the QDrag instance is your own, then you can try calling deleteLater() using its pointer. If that doesn't work, then maybe you will have to redesign your interaction so this problem can't occur.

In my experience, if you start a drag operation and then click the ESC key, this will cancel the drag. I would think that this same interaction mode is supported in Qt. So you could also try posting a QKeyEvent to the QDrag instance to simulate a user key press.

LepaBrena
20th May 2020, 08:38
Tried deleteLater(), ESC key simulating and mouse release simulating but, unfortunately, same problem occurs.

I have no problem when calling QDialog::show(), so I will try to re-implement my code using this method.

Thank you for your replies.