Drawing a line between two mouse clicks
In this recipe, we will learn to display a line between two points, from where the mouse button is clicked till where the mouse button is released on the form. The focus of this recipe is to understand how the mouse press and release events are handled, how the x a and y coordinates where the mouse button is clicked and released are accessed, and how a line is drawn from the location where the mouse button is clicked to the location where the mouse button is released.
How to do it...
The major players in this recipe are the mousePressEvent()
, mouseReleaseEvent()
, and paintEvent()
methods. The mousePressEvent()
and mouseReleaseEvent()
methods are automatically executed whenever the mouse button is clicked or released, respectively. These two methods will be used to access the x and y coordinates where the mouse button is clicked and released. Finally, the paintEvent()
method is used to draw a line between the coordinates that were supplied by the mousePressEvent...