Time for action – making oscillograms selectable
It's time to make our oscillogram widget interactive. We will teach it to add a couple of lines of code to it that let the user select part of the plot. Let's start with storage for the selection. We'll need two integer variables that can be accessed via read-only properties; therefore, add the following two properties to the class (you can initialize them both to -1
) and implement their getters:
Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionChanged) Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionChanged)
The user can change the selection by dragging the mouse cursor over the plot. When the user presses the mouse button over some place in the plot, we'll mark that place as the start of the selection. Dragging the mouse will determine the end of the selection. The scheme for naming events is similar to the paint event; therefore, we need to declare and implement the following two protected methods:
void Widget...