QPen用户绘图时对线条进行设置,包括线宽、颜色、线型等。
void setColor(const QColor &color) | 设置画笔颜色,即线条颜色 |
void setWidth(int width) | 设置线条宽度 |
void setStyle(Qt::PenStyle) | 设置线条样式 |
void setCapStyle(Qt::PenCapStyle pcs) | 设置线条端点样式 |
void setJoinStyle(Qt::PenJoinStyle pcs) | 设置连接样式 |
1. 线条样式:Qt::PenStyle
Qt::NoPen | 0 | no line at all. For example, QPainter::drawRect() fills but does not draw any boundary line. |
Qt::SolidLine | 1 | A plain line. |
Qt::DashLine | 2 | Dashes separated by a few pixels. |
Qt::DotLine | 3 | Dots separated by a few pixels. |
Qt::DashDotLine | 4 | Alternate dots and dashes. |
Qt::DashDotDotLine | 5 | One dash, two dots, one dash, two dots. |
Qt::CustomDashLine | 6 | A custom pattern defined using QPainterPathStroker::setDashPattern(). |
除上述几种基本线条样式外,可以自定义线条样式,自定义线条样式时需要用到setDashOffset()和setDashPattern()函数。
2. 线条端点样式:Qt::PenCapStyle
Qt::FlatCap | 0x00 | 不包含最后一个点 |
Qt::SquareCap | 0x10 | 是一种包含了最后一个点的方形端点,使用半个线宽覆盖 |
Qt::RoundCap | 0x20 | 是包含最后一个点的圆形端点 |
3. 线条连接样式:Qt::PenJoinStyle
Qt::MiterJoin | 0x00 | The outer edges of the lines are extended to meet at an angle, and this area is filled. |
Qt::BevelJoin | 0x40 | The triangular notch between the two lines is filled. |
Qt::RoundJoin | 0x80 | A circular arc between the two lines is filled. |