Search code examples
c++eventsqwt

QwtPlot mouse click event


I need to get x and y coordinates of mouse click on QwtPlot drawing area (not the whole widget!). The problem is that there's only method bool event(QEvent*) that is called on every event. I've found some solutions (http://www.qtcentre.org/archive/index.php/t-9502.html), using QwtPlotPicker but that doesn't work for me, I'm using Qwt 6 and there are no such methods like setSelectionState().

What is other methods for achieving mouse click events on drawing area in QwtPlot?


Solution

  • There's been some changes in Qwt 6 comparing to 5.

    Now we need to set state machine using QwtPlotPicker::setStateMachine(QwtPickerMachine) method. There are a few options (derived classes):

    • QwtPickerClickPointMachine
    • QwtPickerClickRectMachine
    • QwtPickerDragPointMachine
    • QwtPickerDragRectMachine
    • QwtPickerPolygonMachine
    • QwtPickerTrackerMachine

    depending on our needs.

    Next thing we need to do is connect() signal selected(...) from QwtPlotPicker with our custom slot where we can obtain x and y coordinates or other interesting data.