Results 1 to 10 of 10

Thread: mousePressEvent problem

  1. #1
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default mousePressEvent problem

    I have reimplemented mousePressEvent inside of a QGLWidget. It never gets called.

    I have also reimplemented mouseMoveEvent in the same widget (as recounted in an earlier post). It gets called satisfactorily.

    I dont think there is anything odd about my function:

    Qt Code:
    1. void ImageGLView::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(FLOATING_DOT == mouseMode){
    4. QPoint currentPos = event->pos();
    5. lastPos = currentPos;
    6. }
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    and here is the .h
    Qt Code:
    1. protected:
    2.  
    3. void initializeGL();
    4. void paintGL();
    5.  
    6. void mouseMoveEvent(QMouseEvent *event);
    7. void mousePressEvent(QMouseEvent *event);
    To copy to clipboard, switch view to plain text mode 

    Is there something special I need to know about reimplementing mousePressEvents? I tried implementing it on the parent of my QGLWidget, and it indeed got called when I clicked in the non-covered up part of the parent--

    I am setting stereo mode on the QGLWidget, but it doesn't seem to make any difference when I dont do so.

    I'm baffled, and would greatly appreciate any help. My apologies if this seems like a repost, but my last query was asking for help with mouseMoveEvent, and after I solved my move problem and posed my press problem, I never got any responses

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent problem

    How do you know it is not being called?
    Put a break point on the first line and see if it gets caught, may be( FLOATING_DOT == mouseMode ) is false.

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: mousePressEvent problem

    Or replace mouseMoveEvent and mousePressEvent..I mean get the pressEvent just top of the moveEvent and try..

  4. #4
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent problem

    Quote Originally Posted by high_flyer View Post
    How do you know it is not being called?
    Put a break point on the first line and see if it gets caught, may be( FLOATING_DOT == mouseMode ) is false.
    This is how I know it is not being called--I have done just what you suggested

  5. #5
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent problem

    not sure what you mean by this. Are you saying to re-order the functions? Why would that matter?

  6. #6
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent problem

    Quote Originally Posted by zgulser View Post
    Or replace mouseMoveEvent and mousePressEvent..I mean get the pressEvent just top of the moveEvent and try..
    not sure what you mean by this. Are you saying to re-order the functions? Why would that matter?

    ps: sorry about the unquoted reply that probably didn't make much sense with no context, it's early in the workday...

  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: mousePressEvent problem

    Are you saying to re-order the functions?
    Exactly..Once I've faced with such a problem. And after I replace the regarding functions, it was OK.

  8. #8
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mousePressEvent problem

    I was having what sounds like a similar problem recently where a custom QWidget (comprising QPushButton and QSpinBox) was being added to a QMenu as a QWidgetAction. I wanted a click (or mouseReleaseEvent) from the QPushButton to "activate" the QActionWidget.

    I had to do a little work to get the mouseReleaseEvent to propagate through to the QMenu (using this post). I managed to catch execution in QMenu::activate, but d->mouseDown was not set. I think it had to do with clicking on the QPushButton which was not being considered to be "inside" the QWidgetAction and therefore failing to actually properly activate the QWidgetAction. This is the thread.

    I solved my problem with a simple workaround, but would like to get it working using events properly.

    EDIT: I just had a look at your code snippet again. I think you might need to call mousePressEvent on your base class in void ImageGLView::mousePressEvent(QMouseEvent *event).

    i.e.
    Qt Code:
    1. void ImageGLView::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(FLOATING_DOT == mouseMode){
    4. QPoint currentPos = event->pos();
    5. lastPos = currentPos;
    6. }
    7. QBaseClass::mousePressEvent(event);
    8. }
    To copy to clipboard, switch view to plain text mode 

    EDIT: I take it back - I reread you post and I realised that your mousePressEvent isn't even being called. Is the base class mousePressEvent being called when clicking inside QGLWidget (unlikely)? Is the parent's mousePressEvent being called when you click inside the QGLWidget (should happen under normal circumstances, as far as I understand)?
    Last edited by stefanadelbert; 16th April 2010 at 09:25.

  9. #9
    Join Date
    Sep 2008
    Location
    Falmouth, MA, USA
    Posts
    34
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousePressEvent problem

    Quote Originally Posted by stefanadelbert View Post
    I was having what sounds like a similar problem recently where a custom QWidget (comprising QPushButton and QSpinBox) was being added to a QMenu as a QWidgetAction. I wanted a click (or mouseReleaseEvent) from the QPushButton to "activate" the QActionWidget.

    I had to do a little work to get the mouseReleaseEvent to propagate through to the QMenu (using this post). I managed to catch execution in QMenu::activate, but d->mouseDown was not set. I think it had to do with clicking on the QPushButton which was not being considered to be "inside" the QWidgetAction and therefore failing to actually properly activate the QWidgetAction. This is the thread.

    I solved my problem with a simple workaround, but would like to get it working using events properly.

    EDIT: I just had a look at your code snippet again. I think you might need to call mousePressEvent on your base class in void ImageGLView::mousePressEvent(QMouseEvent *event).

    i.e.
    Qt Code:
    1. void ImageGLView::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(FLOATING_DOT == mouseMode){
    4. QPoint currentPos = event->pos();
    5. lastPos = currentPos;
    6. }
    7. QBaseClass::mousePressEvent(event);
    8. }
    To copy to clipboard, switch view to plain text mode 

    EDIT: I take it back - I reread you post and I realised that your mousePressEvent isn't even being called. Is the base class mousePressEvent being called when clicking inside QGLWidget (unlikely)? Is the parent's mousePressEvent being called when you click inside the QGLWidget (should happen under normal circumstances, as far as I understand)?
    no, the base class mousePressEvent is NOT being called,or does it appear that the parents mousePressEvent is being called

  10. #10
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mousePressEvent problem

    The parent's mousePressEvent should get called, unless the event is not being passed up for some reason.

    Maybe try reimplementing mouseReleaseEvent in QGLWidget and see if that is called.

Similar Threads

  1. Replies: 8
    Last Post: 16th April 2010, 09:41
  2. mousePressEvent Problem in Qt4
    By hotjava in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2008, 09:29
  3. QGraphicScene MousePressEvent
    By Spitz in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 21:46
  4. MousePressEvent for QTextEdit
    By anju123 in forum Qt Programming
    Replies: 9
    Last Post: 16th August 2007, 06:08
  5. mousePressEvent
    By mickey in forum Newbie
    Replies: 3
    Last Post: 21st March 2006, 15:36

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.