Results 1 to 7 of 7

Thread: Can't catch DragLeaveEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    You are not checking for the obj receiving the event.
    This should not be a problem, but see if you get at all events from your list:
    Qt Code:
    1. bool MyDialog::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. qDebug() << "Event Filter called with " << event->type();
    4. if(obj == ui->myList)
    5. {
    6. if (event->type() == QEvent::DragLeave) {
    7. qDebug() << event->type() << "= drag leave event.";
    8. return true;
    9. } else if (event->type() == QEvent::DragEnter) {
    10. qDebug() << event->type() << "= drag enter event.";
    11. return true;
    12. }
    13. }
    14. else {
    15. // standard event processing
    16. return QObject::eventFilter(obj, event);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Mar 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    Hi, I changed my code the way you suggested, but I don't see that it changed much with regard to the output I get. Specifically, I still don't get the dragLeaveEvent. I get the regular Enter and Leave events fine (10 and 11 respectively, see here), but not the dragEnter and dragLeave events (60 and 62).

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    The idea was to see if you are getting ANY events from this object.
    Put a debug output before the first if(event()->type()...) statement and see if it gets printed out.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Mar 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    Sorry, I was being unprecise. I changed my code to the following:

    Qt Code:
    1. bool MyDialog::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == ui->myList) {
    4. qDebug() << "Event Filter called with " << event->type();
    5. if (event->type() == QEvent::DragLeave) {
    6. qDebug() << event->type() << "= drag leave event.";
    7. return true;
    8. } else if (event->type() == QEvent::DragEnter) {
    9. qDebug() << event->type() << "= drag enter event.";
    10. return true;
    11. } else if (event->type() == QEvent::Drop) {
    12. qDebug() << event->type() << "= drop event.";
    13. return true;
    14. }
    15. } else {
    16. // standard event processing
    17. return QObject::eventFilter(obj, event);
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Result was as described above.

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    Two things:

    1) List must have DragDropMode set to DragDrop or InternalMove, otherwise drag Enter/Leave events will not be delivered (don't ask why).
    2) For another reason I don't know you can't reliably intercept drag enter/leave events using event filter. Subclass QListWidget and reimplement dragEnterEvent() and dragLeaveEvent().

    Qt Code:
    1. class MyList : public QListWidget
    2. {
    3. public:
    4. MyList( QWidget* parent = 0 ) : QListWidget( parent ) {}
    5.  
    6. void dragEnterEvent( QDragEnterEvent* e )
    7. {
    8. qDebug() << "Enter!";
    9. QListWidget::dragEnterEvent( e );
    10. }
    11.  
    12. void dragLeaveEvent( QDragLeaveEvent* e )
    13. {
    14. qDebug() << "Leave!";
    15. QListWidget::dragLeaveEvent( e );
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 

    Maybe threre are some flags that could alter this behavious but I don't know them.

  6. #6
    Join Date
    Mar 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't catch DragLeaveEvent

    Yeah, I haven't found any way around subclassing either, that's why I posted here. Thanks for your help everyone!

Similar Threads

  1. how to catch qMouseEvent
    By pakine in forum Newbie
    Replies: 4
    Last Post: 27th June 2012, 10:47
  2. Catch a signal
    By Archa4 in forum Newbie
    Replies: 2
    Last Post: 17th February 2011, 09:46
  3. how to catch qMouseEvent
    By pakine in forum Newbie
    Replies: 0
    Last Post: 5th July 2010, 17:16
  4. [QGraphicsItem] isMovable && dragLeaveEvent
    By Spitz in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2008, 09:55
  5. How to catch segfaults?
    By Daliphant in forum Newbie
    Replies: 4
    Last Post: 3rd July 2008, 14:17

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.