PDA

View Full Version : MouseEvent issues with QwtPlot inside QGraphicsScene



MSUdom5
12th April 2013, 17:47
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

Uwe
13th April 2013, 07:29
What am I doing wrong?
Using QwtPlot inside a QGraphicsScene ?

More serious: seems to be an issue with mouse tracking (http://https://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#mouseTracking-prop). Have a look for QEvent::MouseMove events in QwtPicker::eventFilter ( for the zoomer ) and try to find out what's going wrong.

Uwe

MSUdom5
15th April 2013, 14:19
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!

MSUdom5
15th April 2013, 19:44
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...

MSUdom5
16th April 2013, 17:32
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:



void MyPlot::mousePressEvent(QMouseEvent *event) {
QwtPlot::mousePressEvent(event);
event->accept();
}


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! :D