Displaying coordinates where the mouse button is clicked and released
In this recipe, we will be learning to display the x and y coordinates where the mouse button is clicked, along with the coordinates of where the mouse button is released.
How to do it...
Two methods, mousePressEvent() and mouseReleaseEvent(), will play major role in this recipe. The mousePressEvent() method will be automatically invoked when the mouse is pressed and will reveal the x and y coordinates when the mouse press event has occurred. Similarly, the mouseReleaseEvent() method will be invoked automatically whenever the mouse button is released. Two Label widgets will be used in this recipe to display the coordinates where the mouse button is clicked and where the mouse button is released. Here are the steps to create such an application:Â
- Let's create an application based on the
Dialog without Buttonstemplate. - Add three
QLabelwidgets to the form by dragging and dropping threeLabelwidgets on the form. - Set the
text...