Displaying mouse coordinates
To draw any shape with the mouse, you need to know where the mouse button is clicked, to where the mouse is dragged, and where the mouse button is released. Only after knowing the coordinates where the mouse button is clicked can you go ahead and execute commands to draw different shapes. In this recipe, we will be learning to display the x and y coordinates to which the mouse is moved on the form.
How to do it...
In this recipe, we will be tracking mouse movement and will be displaying the x and y coordinates which the mouse is moved on the form. So, in all, we will be using two Label
widgets in this application, one for displaying a message and the other for displaying mouse coordinates. The complete steps for creating this application are shown here:
- Let's create an application based on the
Dialog without Buttons
template. - Add two
QLabel
widgets to the form by dragging and dropping twoLabel
widgets on the form. - Set the
text
property of the firstLabel
widget to...