In this recipe, we will be learning to display lines of different types between two points, from the mouse click location to where the mouse button is released. The user will be shown different line types to choose from, such as solid, dash line, dash-dot line, and so on. The line will be draw in the selected line type.
It is the QPen
class that is used for defining the size or thickness of the pen used for drawing shapes. The setStyle()
method of the QPen
class is used in this recipe to define the style of the line. Here is the step-by-step procedure to draw lines of different styles:
- 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. - Add a
QListWidget
widget by dragging and dropping aList Widget
item on the form. - Set the
text
property of theLabel
widget toSelect the style from the list and then click and drag to draw a line
. - Save the application...