QtBase
v6.3.1
|
The QPen class defines how a QPainter should draw lines and outlines of shapes. More...
#include <qpen.h>
Public Types | |
typedef QPenPrivate * | DataPtr |
Friends | |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &, QPen &) |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &, const QPen &) |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QPen &pen) |
QDataStream & | operator>> (QDataStream &stream, QPen &pen) |
The QPen class defines how a QPainter should draw lines and outlines of shapes.
\inmodule QtGui
A pen has a style(), width(), brush(), capStyle() and joinStyle().
The pen style defines the line type. The brush is used to fill strokes generated with the pen. Use the QBrush class to specify fill styles. The cap style determines the line end caps that can be drawn using QPainter, while the join style describes how joins between two lines are drawn. The pen width can be specified in both integer (width()) and floating point (widthF()) precision. A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the \l {QPainter::Coordinate Transformations}{transformation} set on the painter.
The various settings can easily be modified using the corresponding setStyle(), setWidth(), setBrush(), setCapStyle() and setJoinStyle() functions (note that the painter's pen must be reset when altering the pen's properties).
For example:
which is equivalent to
The default pen is a solid black brush with 1 width, square cap style (Qt::SquareCap), and bevel join style (Qt::BevelJoin).
In addition QPen provides the color() and setColor() convenience functions to extract and set the color of the pen's brush, respectively. Pens may also be compared and streamed.
For more information about painting in general, see the \l{Paint System} documentation.
qpen_default_join QPen::QPen | ( | ) |
QPen::QPen | ( | Qt::PenStyle | style | ) |
Constructs a black pen with 1 width and the given style.
Definition at line 282 of file qpen.cpp.
Constructs a solid line pen with 1 width and the given color.
QPen::QPen | ( | const QBrush & | brush, |
qreal | width, | ||
Qt::PenStyle | style = Qt::SolidLine , |
||
Qt::PenCapStyle | cap = Qt::SquareCap , |
||
Qt::PenJoinStyle | join = Qt::BevelJoin |
||
) |
Constructs a pen with the specified brush, width, pen style, cap style and join style.
QPen::~QPen | ( | ) |
|
inlinenoexcept |
QBrush QPen::brush | ( | ) | const |
Qt::PenCapStyle QPen::capStyle | ( | ) | const |
Returns the pen's cap style.
Definition at line 698 of file qpen.cpp.
QColor QPen::color | ( | ) | const |
Returns the color of this pen's brush.
Definition at line 754 of file qpen.cpp.
qreal QPen::dashOffset | ( | ) | const |
Returns the dash offset for the pen.
Definition at line 542 of file qpen.cpp.
bool QPen::isCosmetic | ( | ) | const |
Returns true
if the pen is cosmetic; otherwise returns false
.
Cosmetic pens are used to draw strokes that have a constant width regardless of any transformations applied to the QPainter they are used with. Drawing a shape with a cosmetic pen ensures that its outline will have the same thickness at different scale factors.
A zero width pen is cosmetic by default.
Definition at line 819 of file qpen.cpp.
bool QPen::isDetached | ( | ) |
bool QPen::isSolid | ( | ) | const |
Returns true
if the pen has a solid fill, otherwise false.
Definition at line 800 of file qpen.cpp.
Qt::PenJoinStyle QPen::joinStyle | ( | ) | const |
Returns the pen's join style.
Definition at line 725 of file qpen.cpp.
qreal QPen::miterLimit | ( | ) | const |
Returns the miter limit of the pen. The miter limit is only relevant when the join style is set to Qt::MiterJoin.
Definition at line 584 of file qpen.cpp.
QPen::operator QVariant | ( | ) | const |
|
inline |
Returns true
if the pen is different from the given pen; otherwise false. Two pens are different if they have different styles, widths or colors.
Definition at line 114 of file qpen.h.
Returns true
if the pen is equal to the given pen; otherwise false. Two pens are equal if they have equal styles, widths and colors.
Definition at line 862 of file qpen.cpp.
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition at line 788 of file qpen.cpp.
void QPen::setCapStyle | ( | Qt::PenCapStyle | style | ) |
Sets the pen's cap style to the given style. The default value is Qt::SquareCap.
Definition at line 712 of file qpen.cpp.
Sets the color of this pen's brush to the given color.
Definition at line 767 of file qpen.cpp.
void QPen::setCosmetic | ( | bool | cosmetic | ) |
Sets this pen to cosmetic or non-cosmetic, depending on the value of cosmetic.
Definition at line 833 of file qpen.cpp.
Sets the dash offset (the starting point on the dash pattern) for this pen to the offset specified. The offset is measured in terms of the units used to specify the dash pattern.
\table \row
However, if the dash offset is set to 4.0, any line drawn will begin with the gap. Values of the offset up to 4.0 will cause part of the stroke to be drawn first, and values of the offset between 4.0 and 6.0 will cause the line to begin with part of the gap. \endtable
Definition at line 565 of file qpen.cpp.
Sets the dash pattern for this pen to the given pattern. This implicitly converts the style of the pen to Qt::CustomDashLine.
The pattern must be specified as an even number of positive entries where the entries 1, 3, 5... are the dashes and 2, 4, 6... are the spaces. For example:
\table 100% \row
The dash pattern is specified in units of the pens width; e.g. a dash of length 5 in width 10 is 50 pixels long. Note that a pen with zero width is equivalent to a cosmetic pen with a width of 1 pixel.
Each dash is also subject to cap styles so a dash of 1 with square cap set will extend 0.5 pixels out in each direction resulting in a total width of 2.
Note that the default cap style is Qt::SquareCap, meaning that a square line end covers the end point and extends beyond it by half the line width.
Definition at line 520 of file qpen.cpp.
void QPen::setJoinStyle | ( | Qt::PenJoinStyle | style | ) |
Sets the pen's join style to the given style. The default value is Qt::BevelJoin.
Definition at line 739 of file qpen.cpp.
Sets the miter limit of this pen to the given limit.
The miter limit describes how far a miter join can extend from the join point. This is used to reduce artifacts between line joins where the lines are close to parallel.
This value does only have effect when the pen style is set to Qt::MiterJoin. The value is specified in units of the pen's width, e.g. a miter limit of 5 in width 10 is 50 pixels long. The default miter limit is 2, i.e. twice the pen width in pixels.
Definition at line 606 of file qpen.cpp.
void QPen::setStyle | ( | Qt::PenStyle | style | ) |
[0]
Sets the pen style to the given style.
See the \l Qt::PenStyle documentation for a list of the available styles. Since Qt 4.1 it is also possible to specify a custom dash pattern using the setDashPattern() function which implicitly converts the style of the pen to Qt::CustomDashLine.
Definition at line 52 of file doc_src_groups.cpp.
void QPen::setWidth | ( | int | width | ) |
Sets the pen width to the given width in pixels with integer precision.
A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the \l {QPainter::Coordinate Transformations}{transformation} set on the painter.
Setting a pen width with a negative value is not supported.
Definition at line 654 of file qpen.cpp.
Sets the pen width to the given width in pixels with floating point precision.
A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the \l {QPainter::Coordinate Transformations}{transformation} on the painter.
Setting a pen width with a negative value is not supported.
Definition at line 680 of file qpen.cpp.
Qt::PenStyle QPen::style | ( | ) | const |
Returns the pen style.
Definition at line 421 of file qpen.cpp.
int QPen::width | ( | ) | const |
Returns the pen width with integer precision.
Definition at line 622 of file qpen.cpp.
qreal QPen::widthF | ( | ) | const |
Returns the pen width with floating point precision.
Definition at line 634 of file qpen.cpp.
|
friend |
|
related |
|
friend |
|
related |