Results 1 to 5 of 5

Thread: MouseEvent issues with QwtPlot inside QGraphicsScene

  1. #1
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default MouseEvent issues with QwtPlot inside QGraphicsScene

    I'm working on a project which requires me to embed a QwtPlot in a QGraphicsScene. I know this may come with some performance issues, but in this particular case it is absolutely necessary.

    The plot shows up just fine, but when I try to interact with it (zooming, panning), the mouse events aren't being captured correctly. Click and drag events don't seem to be recognized. I added the spectrogram plot class from the Qwt examples to test my sanity, and I'm having the same issues. For example, when using the PlotZoomer, I left-click and drag, but while I'm dragging the rubberband doesn't appear. However, when I release, the rubberband appears, but I can't complete the zoom, i.e., the mouse release event doesn't seem to register. I get similar behavior with the PlotPanner.

    What am I doing wrong?

    Thank you,
    MSUdom5

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MouseEvent issues with QwtPlot inside QGraphicsScene

    Quote Originally Posted by MSUdom5 View Post
    What am I doing wrong?
    Using QwtPlot inside a QGraphicsScene ?

    More serious: seems to be an issue with mouse tracking. Have a look for QEvent::MouseMove events in QwtPicker::eventFilter ( for the zoomer ) and try to find out what's going wrong.

    Uwe

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

    MSUdom5 (15th April 2013)

  4. #3
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent issues with QwtPlot inside QGraphicsScene

    Uwe, why are you adverse to including Qwt widget in Qt's graphics framework? I find the ability to draw widgets in a QGraphicsScene pretty powerful, especially in cases where one would need to include plots on a canvas with other graphics items. However, as the developer of the almighty Qwt, I'm sure you can provide more insight.

    I'll look into the eventFilter and see if I can find out what's happening. I have a feeling some events are getting filtered out before making it to the QwtPicker. I'll update once I have more information.

    Thanks!

  5. #4
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: MouseEvent issues with QwtPlot inside QGraphicsScene

    Update:

    In QwtPicker, all events except QEvent::MouseButtonRelease get identified when the plot is embedded in a QGraphicsScene. I'm wondering if it's getting filtered out before it gets to the QwtPlot widget. But why only MouseButtonRelease and no other events? The investigation continues...

  6. #5
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up Re: MouseEvent issues with QwtPlot inside QGraphicsScene

    Solved it!!

    The QGraphicsScene event handler will ignore mouse release events if there is no mouse grabber. As a result, the mouse release event is not passed to the QGraphicsProxyWidget and then to the underlying QWidget. In order to set the QwtPlot as the mouse grabber, the mousePressEvent function needs to be reimplemented as follows:

    Qt Code:
    1. void MyPlot::mousePressEvent(QMouseEvent *event) {
    2. QwtPlot::mousePressEvent(event);
    3. event->accept();
    4. }
    To copy to clipboard, switch view to plain text mode 

    The accept() function sets MyPlot widget as the mouse grabber, and thus, QGraphicsScene will not ignore the mouse release event that follows the mouse press. The mouse release events will be handled, and everything will work as expected.

    Hopefully this information will be useful to someone!

Similar Threads

  1. QwtPlot inside a QGraphicsView
    By gibi70 in forum Qwt
    Replies: 16
    Last Post: 26th February 2013, 21:59
  2. Performance issues QwtPlot
    By ghm in forum Qwt
    Replies: 3
    Last Post: 1st February 2012, 07:33
  3. Replies: 13
    Last Post: 18th December 2009, 09:43
  4. Replies: 0
    Last Post: 4th November 2009, 06:12
  5. QwtPlot inside QScrollArea
    By mastupristi in forum Qwt
    Replies: 3
    Last Post: 13th October 2009, 04:28

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.