In this recipe, we will be learning to display a rectangle between the two points where the mouse button is clicked and released on the form.
Drawing a rectangle between two mouse clicks
How to do it...
It is a very simple application, where the mousePressEvent() and mouseReleaseEvent() methods are used to find the x and y coordinates of the location where the mouse is pressed and released, respectively. Thereafter, the drawRect() method is invoked to draw the rectangle from the coordinates where the mouse button is clicked to the coordinates where the mouse button is released. The step-by-step procedure for creating this application is as follows:
- Let's create an application based on the Dialog without Buttons template.
- Add...