#includeQPen pen(Qt::red); // creates a red pen color pen.setWidth(2); // sets the width of the line to 2 pixels pen.setStyle(Qt::SolidLine); // sets the style of line to solid
#includeThis example sets a dash line style with a blue color and a width of 3 pixels. The cap style is set to be a square and the join style is set to be a miter join. Package library: Qt5WidgetsQPen pen(Qt::blue); pen.setWidth(3); pen.setStyle(Qt::DashLine); pen.setCapStyle(Qt::SquareCap); // sets the cap style to be a square pen.setJoinStyle(Qt::MiterJoin); // sets the join style to be a miter join