Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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.