PDA

View Full Version : Install Event Filter instead of PlotPanner



missoni
11th May 2012, 08:54
Hey!
I had been trying to modify QwtPlotPanner to repaint plot canvas during panning, until I read that this is impossible and I should install an event filter instead, which would catch mouse clicks and repaint the plot using setAxisScale(). I did this, but I the event filter is not called. My code is like the following:


Plot::Plot(QWidget *parent):
QwtPlot(parent)
{
...
createAxes();
createLegend();
installEventFilter(m_eventFilter);
...
installPlotZoomer();
installPlotPicker();
}

where event filter is the following short calss:


class MyEventFilter : public QObject
{
protected:
bool eventFilter(QObject *, QEvent *) {
std::cout << "MyEventFilter::eventFilter()" << std::endl;
return true;
}
};
MyEventFilter is not called. Any ideas why not?

Thank you in advance!

d_stranz
11th May 2012, 17:29
I think you probably need to install the event filter on the canvas, not the plot.

I think that in general, event filters are not stand-alone QObject classes, but are implemented as part of another class, in your case the Plot class. Try making your eventFilter() method a member of Plot. (Note that I am not sure of this, but if you look at the example under QObject::eventFilter(), that's how it is done there).

Besides, how do you know that your event filter isn't being called? Because you don't see anything on std::cout? Because of the potential for buffering and flushing in use of cout, I don't think that is very reliable. Either set a breakpoint inside you event filter and see what happens in the debugger, or use qDebug() instead of std::cout.

Uwe
12th May 2012, 11:30
I had been trying to modify QwtPlotPanner to repaint plot canvas during panning, ...
There are reasons why it is not implemented this way and as long as you don't have a plot where all scales are hidden you are wasting your time.

Uwe