Displaying a point where the mouse button is clicked
In this recipe, we will be learning to display the point where the mouse button is clicked on the form. Point here means a dot. That is, wherever the user presses the mouse, a dot will appear at that coordinate. You will also learn to define the size of the dot too.
How to do it...
The mousePressEvent()
method will be used in this recipe as it is the method that is automatically invoked when the mouse is pressed on the form. In the mousePressEvent()
method, we will execute the command to display a dot or point of the desired size. Here are the steps to understand how you can display a point or dot on the form where the mouse button is clicked:
- Let's create an application based on the
Dialog without Buttons
template. - Add a
QLabel
widgets to the form by dragging and dropping aLabel
widget on the form. - Set the
text
property of theLabel
widget toClick the mouse where you want to display a dot
. - Save the application by name as
demoDrawDot.ui
.
The...