In this recipe, we will be learning to draw a circle. The user will click and drag the mouse to define the diameter of the circle, and the circle will be drawn at the diameter specified by the user.
A circle is nothing but an arc that is drawn from 0 to 360 degrees. The length of the arc, or you can say the diameter of the circle, is determined by the distance of mouse press event and mouse release events. A rectangle is defined internally from mouse press event until mouse release event, and the circle is drawn within that rectangle. Here are the complete steps to create this application:
- Let's create an application based on the
Dialog without Buttons
template. - Add a
QLabel
widget to the form by dragging and dropping aLabel
widget on the form. - Set the
text
property of theLabel
widget toClick the mouse and drag it to draw a circle of the desired size
. - Save the application by name as
demoDrawCircle.ui
. The form will now appear as shown in the...