#include int main(int argc, char **argv) { QApplication a(argc, argv); QPen pen; pen.setColor( QColor(0, 0, 255) ); pen.setWidth(2.0); pen.setCapStyle(Qt::FlatCap); pen.setStyle(Qt::SolidLine); QPainterPath path; path.moveTo(-50, -50); path.lineTo (-50, 50); path.lineTo (50, 50); path.lineTo (50, -50); path.closeSubpath(); QPixmap p(200, 200); p.fill(Qt::white); QPainter painter(&p); painter.translate(100, 100); painter.setPen(pen); painter.drawPath(path); // now switch to custom dashed line... QVector dashes; dashes << 4 << 2; pen.setDashPattern(dashes); pen.setColor(Qt::black); const int x1 = -50; const int x2 = 50; int y = -45; qreal offset = 5.5; for ( int i = 0; i < 20; i++) { pen.setDashOffset(offset); painter.setPen(pen); painter.drawLine(x1, y, x2, y); y += 4; offset -= 0.5; } painter.end(); p.save("test.png", "PNG"); return 0; }