Results 1 to 5 of 5

Thread: mouseevent / clicked

  1. #1
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default mouseevent / clicked

    Hi,
    I made a delegate for a qlistview, all works fine.
    The widget that uses the delegate connects the clicked signal to a slot, works fine.
    But since I added mousepress/release/move events in that delegate, the slot for the clicked signal doesn't fire anymore.

    How do i fix this? Hopefully not by moving the clicked signal/slot to the delegate too, that would be inconvenient.

    Thanks.

  2. #2
    Join Date
    Feb 2012
    Location
    Warsaw, Poland
    Posts
    37
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: mouseevent / clicked

    Show some code, the most important is how you "added mousepress/release/move events in that delegate".
    I guess that you have to do sth like this:
    Qt Code:
    1. bool MyClass::someEvent(Event e)
    2. {
    3. BaseClass::someEvent(e);
    4. //Your code
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to west for this useful post:

    Cremers (13th October 2014)

  4. #3
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: mouseevent / clicked

    Hey thanks, indeed I'm looking for something like that.
    Qt Code:
    1. /*------------------------------------------------------------------------------------*/
    2. ListView::ListView(QWidget * parent) : QListView(parent)
    3. {
    4. //blabla
    5. mousedown = false;
    6. }
    7. //----------------------------------------------------------------------------
    8. void ListView::mousePressEvent(QMouseEvent * event)
    9. {
    10. mousepos = event->pos();
    11. mousedown = true;
    12. }
    13. //----------------------------------------------------------------------------
    14. void ListView::mouseReleaseEvent(QMouseEvent * event)
    15. {
    16. mousedown = false;
    17. }
    18. //----------------------------------------------------------------------------
    19. void ListView::mouseMoveEvent(QMouseEvent * event)
    20. {
    21. if (mousedown)
    22. {
    23. // do the dirty deed
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    I guess in mousePressEvent() in need something like
    QListView:: onclick(?);

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: mouseevent / clicked

    No, in mousePressEvent()/mouseReleaseEvent() you need to ensure the base class processing is called (exactly as west describes) because it is that processing that leads to the detection of a click event in the base class.
    Qt Code:
    1. //----------------------------------------------------------------------------
    2. void ListView::mousePressEvent(QMouseEvent * event)
    3. {
    4. QListView::mousePressEvent();
    5. mousepos = event->pos();
    6. mousedown = true;
    7. }
    To copy to clipboard, switch view to plain text mode 
    There is nothing Qt specific about this basic C++ behaviour of overdden virtual functions (not delegates).

  6. The following user says thank you to ChrisW67 for this useful post:

    Cremers (13th October 2014)

  7. #5
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: mouseevent / clicked

    Thanks that did the trick.

Similar Threads

  1. qt mouseEvent
    By lapdx in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2012, 13:37
  2. Replies: 0
    Last Post: 24th September 2010, 05:37
  3. MouseEvent on a line
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 25th March 2006, 08:52
  4. MouseEvent on QTextEdit
    By Sarma in forum Qt Programming
    Replies: 14
    Last Post: 10th March 2006, 09:49
  5. MouseEvent & QTextEdit
    By Sarma in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 23:06

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.