How it works...
To draw a rectangle between the mouse button pressed and released locations, we will be making use of two methods, mousePressEvent() and mouseReleaseEvent(). The mousePressEvent() method is automatically invoked when a mouse button is pressed and the mouseReleaseEvent() method is automatically invoked when the mouse button is released. In these two methods, we will be simply saving the values of the x and y coordinates where the mouse button is clicked and released respectively. Two arrays, pos1 and pos2, are defined, where the pos1 array stores the x and y coordinates of the location where the mouse button is clicked and the pos2 array stores the x and y coordinates of the location where the mouse button is released. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access