Results 1 to 8 of 8

Thread: qwt mouseEvents

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qwt mouseEvents

    Hi all,

    I have a QwtPlot in my form. And i want to put a vertical line marker when the user right mouse button clicks onto the canvas of the qwtPlot. I have no problem to set markers, but i need to get mouse click events of qwtPlot. I found the setMousePattern in QwtPlotPicker class. I used it, but nothing changed.

    I wonder if QwtPlot has rightButtonClicked signal. or is there anyother way to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwt mouseEvents

    I haven't worked with qwt before, but do they have a mousePressEvent or mouseReleaseEvent anywhere? If you capture these events, then you can use the function, I believe it is event->button( ) or event->buttons( ) to figure out what buttons the user is pressing. If the button is right, then add your code to add your marker line. Hopefully this will help you.

  3. #3
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwt mouseEvents

    Quote Originally Posted by ToddAtWSU View Post
    I haven't worked with qwt before, but do they have a mousePressEvent or mouseReleaseEvent anywhere? If you capture these events, then you can use the function, I believe it is event->button( ) or event->buttons( ) to figure out what buttons the user is pressing. If the button is right, then add your code to add your marker line. Hopefully this will help you.
    I am sorry but these classes have no signals like that. That is what i am actually asking. in qt3, i made some applications using QMouseEvent, QKeyEvent. But i realised that there is a different approach to these events in qwt. There are QwtPickerMachine, QwtEventPattern classes. But, i found no code examples so i dont know how to implement them. I also dont know whether they are what i am looking for or not. But thanks anyway for your interest.

  4. #4
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qwt mouseEvents

    Aren't qwt objects objects based off different Qt objects? If so, all QWidgets have mousePressEvent and mouseReleaseEvent as far as I know. Maybe you could subclass one of these qwt classes and add in the mouse event(s) you want? Just an idea...sorry it's not a better answer.

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

    Default Re: qwt mouseEvents

    QwtPlot is a composite widget - for catching mouse events on its canvas you need to install an event filter for plot->canvas().
    That's exactly what QwtPlotPicker does - guess this is the class, what you are looking for.

    Uwe

  6. #6
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwt mouseEvents

    Quote Originally Posted by Uwe View Post
    QwtPlot is a composite widget - for catching mouse events on its canvas you need to install an event filter for plot->canvas().
    That's exactly what QwtPlotPicker does - guess this is the class, what you are looking for.

    Uwe
    Hi Uwe,

    I also need some sample code. QWT documentation is not enough for me. Can you provide me a sample code for this?

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

    Default Re: qwt mouseEvents

    I'm not sure what you want to implement, but the code below displays a vertical line, while you are pressing the right mouse button on the canvas:

    Qt Code:
    1. QwtPlotPicker *picker = new QwtPlotPicker(plot->canvas());
    2. picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::DragSelection);
    3. picker->setRubberBandPen(QColor(Qt::red));
    4. picker->setRubberBand(QwtPicker::VLineRubberBand);
    5. picker->setMousePattern(QwtPicker::MouseSelect1, Qt::RightButton);
    To copy to clipboard, switch view to plain text mode 

    If you want to add a permanent line, I would use a picker without rubberband and QwtPlotPicker::ClickSelection. Then all you need to do is to connect a slot to the QwtPlotPicker::selected signal ( you get a polygon with one point), where you attach a line marker.

    HTH,
    Uwe

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

    halberdier83 (3rd December 2007)

  9. #8
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwt mouseEvents

    I have trouble with mouseEvents as well.
    I want to send the values the Tracker displays as an Signal when the plot is clicked at that point.

    I tried the following

    Qt Code:
    1. void QSpectrogramPlot::initWidget()
    2. {
    3. delete m_picker;
    4. m_picker = new QwtPicker(this);
    5. connect(m_picker, SIGNAL(selected(const QwtPolygon &)), this, SLOT(OnPickerPointSelected(const QwtPolygon &)));
    6.  
    7. // emit the position of clicks on widget
    8. m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
    9.  
    10. }
    11.  
    12. void QSpectrogramPlot::OnPickerPointSelected(const QwtPolygon & poly)
    13. {
    14. emit selectedPoint(poly[0]);
    15. m_picker->reset();
    16. }
    To copy to clipboard, switch view to plain text mode 

    The rest to make sure that the Polygon is empty at the next click. I do not want it to be filled with points.

    However the reset is not possible to be used - does not compile.

    How would I do it then?

    Also QwtPolygon would be the wrong argument if I want the points of the tracker, which must be QwtPolygonF. So how do I get the points of the tracker instead ?

    EDIT:

    Found a solution
    Qt Code:
    1. m_picker = new QwtPlotPicker(this->canvas());
    2. connect(m_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));
    3.  
    4. // emit the position of clicks on widget
    5. m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
    6.  
    7. }
    8.  
    9. void QSpectrogramPlot::OnPickerPointSelected(const QwtDoublePoint & p)
    10. {
    11. QPointF point = p;
    12. emit selectedPoint(point);
    13. qDebug() << QString("x: %1, y: %2").arg(point.x()).arg(point.y());
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by pospiech; 22nd April 2009 at 13:58.

Similar Threads

  1. QWT introduction
    By nitriles in forum Qwt
    Replies: 4
    Last Post: 28th September 2007, 10:48
  2. Qwt 5.0.2
    By Uwe in forum Qt-based Software
    Replies: 1
    Last Post: 20th September 2007, 18:21
  3. How to upgrade Qwt 5.0.1 to Qwt 5.0.2
    By luffy27 in forum Qwt
    Replies: 1
    Last Post: 15th July 2007, 19:55
  4. Qwt 5.0.1
    By Uwe in forum Qt-based Software
    Replies: 0
    Last Post: 26th February 2007, 21:24
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 11:24

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.