|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPen
public class QPen
The QPen
class defines how a QPainter
should draw lines and outlines of shapes. 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 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:
QPainter painter = new QPainter(this); QPen pen = new QPen(QColor.green, 3, Qt.PenStyle.DashDotLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin); painter.setPen(pen);which is equivalent to
QPainter painter = new QPainter(this); QPen pen = new QPen(); // creates a default pen pen.setStyle(Qt.PenStyle.DashDotLine); pen.setWidth(3); pen.setBrush(new QBrush(QColor.green)); pen.setCapStyle(Qt.PenCapStyle.RoundCap); pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin); painter.setPen(pen);The default pen is a solid black brush with 0 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 Paint System documentation.
Qt::PenStyle
enum: ![]() | ![]() | ![]() |
Qt::SolidLine | Qt::DashLine | Qt::DotLine |
![]() | ![]() | ![]() |
Qt::DashDotLine | Qt::DashDotDotLine | Qt::CustomDashLine |
setStyle()
function to convert the pen style to either of the built-in styles, except the Qt::CustomDashLine
style which we will come back to shortly. Setting the style to Qt::NoPen
tells the painter to not draw lines or outlines. The default pen style is Qt::SolidLine
. 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
. The pattern argument, a QVector, must be specified as an even number of qreal entries where the entries 1, 3, 5... are the dashes and 2, 4, 6... are the spaces. For example, the custom pattern shown above is created using the following code:
QPen pen = new QPen(); List<Double> dashes = new ArrayList<Double>(); double space = 4; dashes.add(1.0); dashes.add(space); dashes.add(3.0); dashes.add(space); dashes.add(9.0); dashes.add(space); dashes.add(27.0); dashes.add(space); dashes.add(9.0); pen.setDashPattern(dashes);Note that 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.
The currently set dash pattern can be retrieved using the dashPattern()
function. Use the isSolid()
function to determine whether the pen has a solid fill, or not.Cap Style
The cap style defines how the end points of lines are drawn using QPainter
. The cap style only apply to wide lines, i.e. when the width is 1 or greater. The Qt::PenCapStyle
enum provides the following styles:
![]() | ![]() | ![]() |
Qt::SquareCap | Qt::FlatCap | Qt::RoundCap |
Qt::SquareCap
style is a square line end that covers the end point and extends beyond it by half the line width. The Qt::FlatCap
style is a square line end that does not cover the end point of the line. And the Qt::RoundCap
style is a rounded line end covering the end point. The default is Qt::SquareCap
.
Whether or not end points are drawn when the pen width is 0 or 1 depends on the cap style. Using Qt::SquareCap
or Qt::RoundCap
they are drawn, using Qt::FlatCap
they are not drawn.Join Style
The join style defines how joins between two connected lines can be drawn using QPainter
. The join style only apply to wide lines, i.e. when the width is 1 or greater. The Qt::PenJoinStyle
enum provides the following styles:
![]() | ![]() | ![]() |
Qt::BevelJoin | Qt::MiterJoin | Qt::RoundJoin |
Qt::BevelJoin
style fills the triangular notch between the two lines. The Qt::MiterJoin
style extends the lines to meet at an angle. And the Qt::RoundJoin
style fills a circular arc between the two lines. The default is Qt::BevelJoin
.
Qt::MiterJoin
style is applied, it is possible to use the setMiterLimit()
function to specify how far the miter join can extend from the join point. The miterLimit()
is used to reduce artifacts between line joins where the lines are close to parallel. The miterLimit()
must be specified in units of the pens 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.
![]() | The Path Stroking Demo The Path Stroking demo shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns. |
QPainter
, QBrush
, Path Stroking Demo, and Scribble Example.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
static QPen |
NoPen
|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QPen()
Constructs a default black solid line pen with 0 width. |
|
QPen(QBrush brush,
double width)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QBrush brush,
double width,
Qt.PenStyle s)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QBrush brush,
double width,
Qt.PenStyle s,
Qt.PenCapStyle c)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QBrush brush,
double width,
Qt.PenStyle s,
Qt.PenCapStyle c,
Qt.PenJoinStyle j)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QColor color)
Constructs a solid line pen with 0 width and the given color. |
|
QPen(QColor color,
double width)
This is an overloaded constructor provided for convenience. |
|
QPen(QColor color,
double width,
Qt.PenStyle s)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QColor color,
double width,
Qt.PenStyle s,
Qt.PenCapStyle c)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QColor color,
double width,
Qt.PenStyle s,
Qt.PenCapStyle c,
Qt.PenJoinStyle j)
Constructs a pen with the specified brush, width, pen style, cap style and join style. |
|
QPen(QPen pen)
Constructs a pen that is a copy of the given pen. |
|
QPen(Qt.PenStyle arg__1)
Constructs a black pen with 0 width and the given style. |
Method Summary | |
---|---|
QBrush |
brush()
Returns the brush used to fill strokes generated with this pen. |
Qt.PenCapStyle |
capStyle()
Returns the pen's cap style. |
QPen |
clone()
This method is reimplemented for internal reasons |
QColor |
color()
Returns the color of this pen's brush. |
double |
dashOffset()
Returns the dash offset for the pen. |
java.util.List |
dashPattern()
Returns the dash pattern of this pen. |
boolean |
isCosmetic()
Returns true if the pen is cosmetic; otherwise returns false. |
boolean |
isSolid()
Returns true if the pen has a solid fill, otherwise false. |
Qt.PenJoinStyle |
joinStyle()
Returns the pen's join style. |
double |
miterLimit()
Returns the miter limit of the pen. |
void |
readFrom(QDataStream arg__1)
|
void |
setBrush(QBrush brush)
Sets the brush used to fill strokes generated with this pen to the given brush. |
void |
setCapStyle(Qt.PenCapStyle pcs)
Sets the pen's cap style to the given style. |
void |
setColor(QColor color)
Sets the color of this pen's brush to the given color. |
void |
setCosmetic(boolean cosmetic)
Sets this pen to cosmetic or non-cosmetic, depending on the value of cosmetic. |
void |
setDashOffset(double doffset)
Sets the dash offset for this pen to the given offset. |
void |
setDashPattern(java.util.List pattern)
Sets the dash pattern for this pen to the given pattern. |
void |
setJoinStyle(Qt.PenJoinStyle pcs)
Sets the pen's join style to the given style. |
void |
setMiterLimit(double limit)
Sets the miter limit of this pen to the given limit. |
void |
setStyle(Qt.PenStyle arg__1)
Sets the pen style to the given style. |
void |
setWidth(int width)
Sets the pen width to the given width in pixels with integer precision. |
void |
setWidthF(double width)
Sets the pen width to the given width in pixels with floating point precision. |
Qt.PenStyle |
style()
Returns the pen style. |
java.lang.String |
toString()
|
int |
width()
Returns the pen width with integer precision. |
double |
widthF()
Returns the pen width with floating point precision. |
void |
writeTo(QDataStream arg__1)
|
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public static final QPen NoPen
Constructor Detail |
---|
public QPen()
public QPen(Qt.PenStyle arg__1)
setStyle()
.
public QPen(QBrush brush, double width, Qt.PenStyle s, Qt.PenCapStyle c)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QBrush brush, double width, Qt.PenStyle s)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QBrush brush, double width)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QBrush brush, double width, Qt.PenStyle s, Qt.PenCapStyle c, Qt.PenJoinStyle j)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QColor color)
setBrush()
, and setColor()
.
public QPen(QPen pen)
public QPen(QColor color, double width, Qt.PenStyle s, Qt.PenCapStyle c, Qt.PenJoinStyle j)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QColor color, double width, Qt.PenStyle s, Qt.PenCapStyle c)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QColor color, double width, Qt.PenStyle s)
setBrush()
, setWidth()
, setStyle()
, setCapStyle()
, and setJoinStyle()
.
public QPen(QColor color, double width)
Method Detail |
---|
public final QBrush brush()
setBrush()
.
public final Qt.PenCapStyle capStyle()
setCapStyle()
, and Cap Style
.
public final QColor color()
brush()
, and setColor()
.
public final double dashOffset()
setDashOffset()
.
public final java.util.List dashPattern()
setDashPattern()
, style()
, and isSolid()
.
public final boolean isCosmetic()
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; pens with a non-zero width are non-cosmetic.
setCosmetic()
, and widthF()
.
public final boolean isSolid()
style()
, and dashPattern()
.
public final Qt.PenJoinStyle joinStyle()
setJoinStyle()
, and Join Style
.
public final double miterLimit()
Qt::MiterJoin
. setMiterLimit()
, and Join Style
.
public final void writeTo(QDataStream arg__1)
public final void readFrom(QDataStream arg__1)
public final void setBrush(QBrush brush)
brush()
, and setColor()
.
public final void setCapStyle(Qt.PenCapStyle pcs)
Qt::SquareCap
. capStyle()
, and Cap Style
.
public final void setColor(QColor color)
setBrush()
, and color()
.
public final void setCosmetic(boolean cosmetic)
isCosmetic()
.
public final void setDashOffset(double doffset)
Qt::CustomDashLine
. dashOffset()
.
public final void setDashPattern(java.util.List pattern)
Qt::CustomDashLine
. The pattern must be specified as an even number of entries where the entries 1, 3, 5... are the dashes and 2, 4, 6... are the spaces. For example:
![]() | QPen pen = new QPen(); List<Double> dashes = new ArrayList<Double>(); double space = 4; dashes.add(1.0); dashes.add(space); dashes.add(3.0); dashes.add(space); dashes.add(9.0); dashes.add(space); dashes.add(27.0); dashes.add(space); dashes.add(9.0); pen.setDashPattern(dashes); |
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.
setStyle()
, dashPattern()
, setCapStyle()
, and setCosmetic()
.
public final void setJoinStyle(Qt.PenJoinStyle pcs)
Qt::BevelJoin
. joinStyle()
, and Join Style
.
public final void setMiterLimit(double limit)
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.
miterLimit()
, setJoinStyle()
, and Join Style
.
public final void setStyle(Qt.PenStyle arg__1)
See the 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
.
style()
, and Pen Style
.
public final void setWidth(int width)
A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation
set on the painter.
Setting a pen width with a negative value is not supported.
setWidthF()
, and width()
.
public final void setWidthF(double width)
A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation
on the painter.
Setting a pen width with a negative value is not supported.
setWidth()
, and widthF()
.
public final Qt.PenStyle style()
setStyle()
, and Pen Style
.
public final int width()
setWidth()
, and widthF()
.
public final double widthF()
setWidthF()
, and width()
.
public java.lang.String toString()
toString
in class java.lang.Object
public QPen clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |