Results 1 to 3 of 3

Thread: Install Event Filter instead of PlotPanner

  1. #1
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Install Event Filter instead of PlotPanner

    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:
    Qt Code:
    1. Plot::Plot(QWidget *parent):
    2. QwtPlot(parent)
    3. {
    4. ...
    5. createAxes();
    6. createLegend();
    7. installEventFilter(m_eventFilter);
    8. ...
    9. installPlotZoomer();
    10. installPlotPicker();
    11. }
    To copy to clipboard, switch view to plain text mode 
    where event filter is the following short calss:
    Qt Code:
    1. class MyEventFilter : public QObject
    2. {
    3. protected:
    4. bool eventFilter(QObject *, QEvent *) {
    5. std::cout << "MyEventFilter::eventFilter()" << std::endl;
    6. return true;
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 
    MyEventFilter is not called. Any ideas why not?

    Thank you in advance!
    Last edited by missoni; 11th May 2012 at 09:04.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Install Event Filter instead of PlotPanner

    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.

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

    Default Re: Install Event Filter instead of PlotPanner

    Quote Originally Posted by missoni View Post
    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

Similar Threads

  1. Event filter: very confused about how they work
    By papillon in forum Qt Programming
    Replies: 8
    Last Post: 20th November 2011, 00:46
  2. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08
  3. problem with event filter compile for S60
    By jimiq in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th July 2010, 19:48
  4. Event Filter & No Focus problem
    By AlexanderPopov in forum Newbie
    Replies: 0
    Last Post: 22nd December 2009, 20:15
  5. Q3Table event filter problem
    By batileon in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 10:40

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.