Results 1 to 8 of 8

Thread: Issue while overloading mouseReleaseEvent

  1. #1
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Issue while overloading mouseReleaseEvent

    Hi,

    I have a strange issue between a QPushButton and my QToolBar. Basically, I override QPushButton to support right click events. When a user right click on the button, I overide mouseReleaseEvent and it emits a new custom signal. Another class deriving from QWidget connect this signal to a local slot. If this slot call a exec() method from a dialog, the dialog appear ok, but when the dialog close, a QMenu appear. This QMenu is the one generated by QToolBar when right clicking on the toolbar. As far as I'm concerned, the button and the toolbar are unrelated and the mouse was no where near the toolbar on the right click event.

    So I can only assume that the right click event somehow propaged itself to the toolbar. If I change the exec() for a show() (and declare the dialog static), I don't see this problem.

    I'm not sure if this description is clear enough... I will wait before posting a bunch of code.

    Somebody has an idea?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issue while overloading mouseReleaseEvent

    A minimal compileable program would be nice to do some tests. One thing came in my mind while reading. Try if it helps if you call QEvent::accept() in the event handler of your button.

  3. #3
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue while overloading mouseReleaseEvent

    Hi, Thanks for your answer.

    Accepting the event didn't change the behavior... I will work on a small example to recreate the problem.

  4. #4
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue while overloading mouseReleaseEvent

    Here is a small example showing the problem... I'm attaching the files if somebody want to try it out. Since this example is so small, the problem must come for the derived class of QPushButton. Here is the code:

    .h
    Qt Code:
    1. #ifndef MULTI_MOUSE_CLICK_BUTTON_H
    2. #define MULTI_MOUSE_CLICK_BUTTON_H
    3.  
    4. #include <QPushButton>
    5.  
    6. class multiMouseClickButton : public QPushButton
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11.  
    12. multiMouseClickButton(QWidget* myParent = 0);
    13.  
    14. signals:
    15.  
    16. void multiMouseLeftClicked();
    17. void multiMouseMiddleClicked();
    18. void multiMouseRightClicked();
    19.  
    20. protected:
    21.  
    22. void mousePressEvent(QMouseEvent*);
    23. void mouseReleaseEvent(QMouseEvent*);
    24.  
    25. private:
    26. };
    27.  
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include <QMouseEvent>
    2.  
    3. #include "multiMouseClickButton.h"
    4.  
    5. multiMouseClickButton::multiMouseClickButton(QWidget* myParent)
    6. : QPushButton(myParent)
    7. {
    8. }
    9.  
    10. void multiMouseClickButton::mousePressEvent(QMouseEvent* myEvent)
    11. {
    12. setDown( true );
    13. }
    14.  
    15. void multiMouseClickButton::mouseReleaseEvent(QMouseEvent* myEvent)
    16. {
    17. if(isDown())
    18. {
    19. switch(myEvent->button())
    20. {
    21. case Qt::LeftButton:
    22. emit(multiMouseLeftClicked());
    23. break;
    24.  
    25. case Qt::MidButton:
    26. emit(multiMouseMiddleClicked());
    27. break;
    28.  
    29. case Qt::RightButton:
    30. emit(multiMouseRightClicked());
    31. break;
    32.  
    33. default:
    34. break;
    35. }
    36. }
    37.  
    38. setDown( false );
    39. }
    To copy to clipboard, switch view to plain text mode 
    [ATTACH]qt_test.zip[/ATTACH]

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issue while overloading mouseReleaseEvent

    I'm sorry, but it works fine on my computer. (last Kubuntu and Qt 4.6.1)

    right click on the button => dialogue appears => click there ok => dialogue disappears => NO context menu.

  6. #6
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue while overloading mouseReleaseEvent

    I'm using Qt4.5 on mingw... Maybe it's a bug related to this specific config.

    I will try with mingw/Qt4.6 and on a Linux box.

    This what I'm getting after a right click with this code:

    test.jpg

  7. #7
    Join Date
    Feb 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue while overloading mouseReleaseEvent

    It's working on Linux.

    I tried on Qt4.6 mingw (the latest February 2010 release) and the issue is still there. Apparently this is a Qt bug on mingw.

    I'm not sure where should I go from here... I guess I will report the problem.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Issue while overloading mouseReleaseEvent

    Quote Originally Posted by Thierry View Post
    I'm not sure where should I go from here... I guess I will report the problem.
    Strange. Yes, open a new ticket on the Qt Bug Tracker (if it does not exist a similar ticket.)

Similar Threads

  1. mousePressEvent & mouseReleaseEvent question
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 9th December 2009, 07:55
  2. Widget that receives the mouseReleaseEvent
    By qtUser500 in forum Newbie
    Replies: 10
    Last Post: 16th July 2009, 15:33
  3. Strange mouseReleaseEvent behaviour.
    By ricardo in forum Newbie
    Replies: 11
    Last Post: 5th May 2009, 23:35
  4. Child Widget is hogging the MouseReleaseEvent
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2009, 18:28
  5. overloading ++ --
    By mickey in forum General Programming
    Replies: 13
    Last Post: 4th January 2008, 18:55

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.