#include#include void MainWindow::paintEvent(QPaintEvent *){ QPainter painter; painter.begin(this); QPen pen(Qt::black); pen.setStyle(Qt::SolidLine); pen.setWidth(20); QPointF p1[3] = { QPointF(30.0, 80.0),QPointF(20.0, 40.0), QPointF(80.0, 60.0) }; QPointF p2[3] = { QPointF(130.0, 80.0), QPointF(120.0, 40.0), QPointF(180.0, 60.0) }; QPointF p3[3] = { QPointF(230.0, 80.0), QPointF(220.0, 40.0), QPointF(280.0, 60.0) }; pen.setJoinStyle(Qt::MiterJoin); painter.setPen(pen); painter.drawPolyline(p1, 3); pen.setJoinStyle(Qt::BevelJoin); painter.setPen(pen); painter.drawPolyline(p2, 3); pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen); painter.drawPolyline(p3, 3); painter.end();}
画笔的连接风格
#include#include void MainWindow::paintEvent(QPaintEvent *){ QPainter painter; painter.begin(this); QPen pen(Qt::black); pen.setStyle(Qt::SolidLine); pen.setWidth(20); pen.setCapStyle(Qt::FlatCap); painter.setPen(pen); painter.drawLine(30, 30, 200, 30); pen.setCapStyle(Qt::SquareCap); painter.setPen(pen); painter.drawLine(30, 70, 200, 70); pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); painter.drawLine(30, 110, 200, 110); painter.end();}
画笔的三种边角。
void MainWindow::paintEvent(QPaintEvent *){ QPainter painter; painter.begin(this); QRect rect1(10.0, 20.0, 80.0, 50); QRect rect2(110.0, 20.0, 80.0, 50.0); QRect rect3(210.0, 20.0, 80.0, 50.0); QRect rect4(10.0, 100.0, 80.0, 50.0); QRect rect5(110.0, 100.0, 80.0, 50.0); QRect rect6(210.0, 100.0, 80.0, 50.0); QPen pen(Qt::blue, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); painter.setPen(pen); painter.drawEllipse(rect1); //画椭圆 pen.setStyle(Qt::DashLine); painter.setPen(pen); painter.drawEllipse(rect2); pen.setStyle(Qt::DotLine); painter.setPen(pen); painter.drawEllipse(rect3); pen.setStyle(Qt::DashDotLine); painter.setPen(pen); painter.drawEllipse(rect4); pen.setStyle(Qt::DashDotDotLine); painter.setPen(pen); painter.drawEllipse(rect5); pen.setStyle(Qt::CustomDashLine); painter.setPen(pen); painter.drawEllipse(rect6); painter.end();}
设置画笔的轮廓
--