Results 1 to 4 of 4

Thread: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?

  1. #1
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?

    I'm using this code, but the editorEvent doesn't called in a "leave" event.
    And the mouse move don't capture events outside the item rect

    Qt Code:
    1. bool DownloadItemDelegate::editorEvent(
    2. QEvent* event,
    3. const QStyleOptionViewItem& option,
    4. const QModelIndex &index)
    5. {
    6. if (event->type() == QEvent::MouseButtonPress)
    7. {
    8. QMouseEvent* e = (QMouseEvent*)event;
    9.  
    10. if (index.data(Qt::UserRole).toRect().contains(e->pos())) // button "resume"
    11. {
    12. model->setData(index, true, Qt::UserRole + 1); // button pressed (visual-only | button style = sunken)
    13. model->setData(index, true, Qt::UserRole + 2); // button pressed (is clicked?)
    14. return true;
    15. }
    16. }
    17. else if (event->type() == QEvent::MouseButtonRelease)
    18. {
    19. QMouseEvent* e = (QMouseEvent*)event;
    20.  
    21. if (index.data(Qt::UserRole).toRect().contains(e->pos()))
    22. {
    23. model->setData(index, false, Qt::UserRole + 1); // button style = enabled
    24.  
    25. if (index.data(Qt::UserRole + 2).toBool()) // is clicked == true | emit resume();
    26. {
    27. //emit resume_pressed;
    28. }
    29.  
    30. return true;
    31. }
    32.  
    33. model->setData(index, false, Qt::UserRole + 2); // clear this flag
    34. }
    35. else if (event->type() == QEvent::MouseMove)
    36. {
    37. QMouseEvent* e = (QMouseEvent*)event;
    38.  
    39. if (!index.data(Qt::UserRole).toRect().contains(e->pos())) // if exit button rect, button style = enabled
    40. {
    41. model->setData(index, false, Qt::UserRole + 1);
    42. return true;
    43. }
    44. else if (index.data(Qt::UserRole + 2).toBool()) // if enter button rect, and, the checked flag is true, button style = sunken
    45. {
    46. model->setData(index, true, Qt::UserRole + 1);
    47. return true;
    48. }
    49. }
    50.  
    51. return false;
    52. }
    To copy to clipboard, switch view to plain text mode 

    This handles the basics of a QPushButton that I need, but, how can I check if the mouse leave the item region ?
    I need to check this event to clear the flags of the button.
    Last edited by rsilva; 16th May 2011 at 02:18.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?

    You will not catch a leaveEvent this way as the cursor is not over the item anymore so a different item will start receiving events. That's your clue that the cursor has left the item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?

    So, the solution is to remove the pressed flag from the event function of all other widgets, when they get an event? Does not seem right.

  4. #4
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How I can use a "Mouse Leave" event inside QItemDelegate::editorEvent ?

    with the MouseOver option flag like described here it works: http://www.qtcentre.org/threads/1314...te-enter-event

Similar Threads

  1. Replies: 2
    Last Post: 20th March 2010, 18:22
  2. How to "sleep" inside QRunnable-derived class?
    By TorAn in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2009, 22:03
  3. Mouse Leave and Tab Key event in Delegate
    By faldzip in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2008, 19:04
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. Replies: 7
    Last Post: 20th November 2007, 12:15

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.