Results 1 to 5 of 5

Thread: Cannot cancel Drag when Dialog exec() is fired [Windows]

  1. #1

    Default Cannot cancel Drag when Dialog exec() is fired [Windows]

    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.

    Qt Code:
    1. int myDialog::exec()
    2. {
    3. getActiveDrag()->cancel();
    4.  
    5. QTime dieTime= QTime::currentTime().addSecs(1);
    6.  
    7. while (QTime::currentTime() < dieTime)
    8. {
    9. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    10. }
    11.  
    12. return QDialog::exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cannot cancel Drag when Dialog exec() is fired [Windows]

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

    Default Re: Cannot cancel Drag when Dialog exec() is fired [Windows]

    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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Cannot cancel Drag when Dialog exec() is fired [Windows]

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5

    Default Re: Cannot cancel Drag when Dialog exec() is fired [Windows]

    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.

Similar Threads

  1. Replies: 16
    Last Post: 11th June 2014, 08:16
  2. Strange failure (dialog exec close qt 5.1)
    By giancarlo.fir in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 29th October 2013, 11:07
  3. Replies: 1
    Last Post: 15th August 2009, 12:23
  4. mouseMoveEvent during drag is not fired
    By gruszczy in forum Qt Programming
    Replies: 7
    Last Post: 24th February 2009, 22:04
  5. QDialog::exec() cereates no modal dialog
    By sboesch in forum Qt Programming
    Replies: 8
    Last Post: 27th March 2006, 18:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.