#includeint main(int argc, char* argv[]) { QPainterPath path; path.moveTo(10, 10); path.lineTo(50, 50); path.lineTo(50, 10); path.lineTo(10, 10); return 0; }
#includeThis code creates a QPainterPath object for a line segment and sets up a vector of dash lengths and gaps. A QPainter object is used to draw the path on the screen with the set pattern. Package library: Qt#include int main(int argc, char* argv[]) { QPainter painter; QPainterPath dashPath; dashPath.moveTo(10, 10); dashPath.lineTo(50, 50); QVector dashes; dashes << 5 << 2 << 5 << 2; // define the pattern of dashes and gaps painter.drawPath(dashPath); return 0; }