Results 1 to 11 of 11

Thread: QTextEdit eventfilter MouseButtonDblClick

  1. #1
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default QTextEdit eventfilter MouseButtonDblClick

    The eventfilter() for QTextEdit is not catching the MouseButtonDblClick from the mouse button. It is catching it from the mouse wheel!
    Also, everything works fine if I derive QTextEdit and reimplement void mouseDoubleClickEvent(QMouseEvent * event);
    I'd prefer to not derive QTextEdit.

    Is this behavior a Windows feature? Windows 7, Qt 5.1.1
    Last edited by Henry Blue Heeler; 9th April 2015 at 02:47.

  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: QTextEdit eventfilter MouseButtonDblClick

    Install the filter on the viewport rather than the text edit itself.
    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
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit eventfilter MouseButtonDblClick

    I did install it on the text edit's viewport, to no avail. I should have mentioned that.

  4. #4
    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: QTextEdit eventfilter MouseButtonDblClick

    Please prepare a minimal compilable example reproducing the problem.
    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.


  5. The following user says thank you to wysota for this useful post:

    Henry Blue Heeler (9th April 2015)

  6. #5
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit eventfilter MouseButtonDblClick

    Pilot error! The event filter:
    Qt Code:
    1. textEdit->viewport()->installEventFilter(this);
    2. ...
    3. bool Dialog::eventFilter(QObject* obj, QEvent* event)
    4. {
    5. if( obj == textEdit ) // Wrong!! since the event filter was installed on the viewport, we need the parent
    6. {
    7. if (event->type() == QEvent::MouseButtonDblClick)
    8. {
    9. }
    10. }
    11. }
    12.  
    13. bool Dialog::eventFilter(QObject* obj, QEvent* event)
    14. {
    15. if( obj->parent()== textEdit ) // Correct!
    16. {
    17. if (event->type() == QEvent::MouseButtonDblClick)
    18. {
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Henry Blue Heeler; 9th April 2015 at 23:00. Reason: Fixed it.

  7. #6
    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: QTextEdit eventfilter MouseButtonDblClick

    I suggest to test against obj == textEdit->viewport() rather than obj->parent() == textEdit.
    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.


  8. The following user says thank you to wysota for this useful post:

    Henry Blue Heeler (10th April 2015)

  9. #7
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit eventfilter MouseButtonDblClick

    Either works. Are you thinking perhaps the viewport's parent may change?
    I can see that obj == textEdit->viewport() has more certainty.
    Regardless, thanks again for the help.
    Last edited by Henry Blue Heeler; 10th April 2015 at 00:10. Reason: Solved

  10. #8
    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: QTextEdit eventfilter MouseButtonDblClick

    Quote Originally Posted by Henry Blue Heeler View Post
    Either works. Are you thinking perhaps the viewport's parent may change?
    I am thinking that you are testing against the object you really want to test against instead of testing a relation which may be true for more than one object. If you are expecting "4", test against "4" and not "an even number".
    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.


  11. #9
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit eventfilter MouseButtonDblClick

    Yes, the object (viewport) could have multiple parents (unlikely in this scenario), but I get the nuance. Better practice, per se. Thx.

  12. #10
    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: QTextEdit eventfilter MouseButtonDblClick

    Quote Originally Posted by Henry Blue Heeler View Post
    Yes, the object (viewport) could have multiple parents
    No. The text edit may have (and indeed has) multiple children.
    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.


  13. #11
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QTextEdit eventfilter MouseButtonDblClick

    Quote Originally Posted by wysota View Post
    No. The text edit may have (and indeed has) multiple children.
    Good point! Thx.

Similar Threads

  1. Replies: 12
    Last Post: 16th February 2014, 15:28
  2. EventFilter problem
    By aruval3 in forum Qt Programming
    Replies: 10
    Last Post: 17th November 2011, 22:22
  3. Autorepeat within eventfilter
    By Patrick_Bao in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2010, 08:37
  4. QTreeWidget and eventFilter
    By luoyes in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 07:38
  5. Replies: 2
    Last Post: 10th April 2009, 03:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.