![]() |
Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions | ![]() |
The QPen class defines how a QPainter should draw lines and outlines of shapes. More...
#include <QPen>
Part of the QtGui module.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
A pen has a style, width, brush, cap style and join style.
The pen style defines the line type. The default pen style is Qt::SolidLine. Setting the style to Qt::NoPen tells the painter to not draw lines or outlines.
The pen brush defines the fill of lines and text. The default pen is a solid black brush. The QColor documentation lists predefined colors.
The cap style defines how the end points of lines are drawn. The join style defines how the joins between two lines are drawn when multiple connected lines are drawn (QPainter::drawPolyline() etc.). The cap and join styles only apply to wide lines, i.e. when the width is 1 or greater.
Use the QBrush class to specify fill styles.
Example:
QPainter painter; QPen pen(red, 2); // red solid line, 2 pixels wide painter.begin(&anyPaintDevice); // paint something painter.setPen(pen); // set the red, wide pen painter.drawRect(40,30, 200,100); // draw a rectangle painter.setPen(blue); // set blue pen, 0 pixel width painter.drawLine(40,30, 240,130); // draw a diagonal in rectangle painter.end(); // painting done
See the Qt::PenStyle enum type for a complete list of pen styles.
With reference to the end points of lines, for wide (non-0-width) pens it depends on the cap style whether the end point is drawn or not. QPainter will try to make sure that the end point is drawn for 0-width pens, but this cannot be absolutely guaranteed because the underlying drawing engine is free to use any (typically accelerated) algorithm for drawing 0-width lines. On all tested systems, however, the end point of at least all non-diagonal lines are drawn.
A pen's color(), brush(), width(), style(), capStyle() and joinStyle() can be set in the constructor or later with setColor(), setWidth(), setStyle(), setCapStyle() and setJoinStyle(). Pens may also be compared and streamed.
See also QPainter and QPainter::setPen().
Constructs a default black solid line pen with 0 width, which renders lines 1 pixel wide (fast diagonals).
Constructs a black pen with 0 width and style style.
See also setStyle().
Constructs a pen of color color with 0 width.
See also setBrush() and setColor().
Constructs a pen with the specified brush brush and width width. The pen style is set to s, the pen cap style to c and the pen join style to j.
See also setWidth(), setStyle(), and setBrush().
Constructs a pen that is a copy of p.
Destroys the pen.
Returns the brush used to fill strokes generated with this pen.
Returns the pen's cap style.
See also setCapStyle().
Returns the pen color.
See also setColor().
Returns true if the pen has a solid fill
Returns the pen's join style.
See also setJoinStyle().
Sets the brush used to fill strokes generated with this pen.
Sets the pen's cap style to c.
The default value is Qt::FlatCap. The cap style has no effect on 0-width pens.
Warning: On Windows 95/98 and Macintosh, the cap style setting has no effect. Wide lines are rendered as if the cap style was Qt::SquareCap.
See also capStyle().
Sets the pen color to c.
See also color().
Sets the pen's join style to j.
The default value is Qt::MiterJoin. The join style has no effect on 0-width pens.
See also joinStyle().
Sets the pen style to s.
See the Qt::PenStyle documentation for a list of all the styles.
Warning: On Windows 95/98 and Macintosh, the style setting (other than Qt::NoPen and Qt::SolidLine) has no effect for lines with width greater than 1.
See also style().
Sets the pen width to width
Sets the pen width to width.
A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate algorithm for diagonals. For horizontal and vertical lines a line width of 0 is the same as a line width of 1. The cap and join style have no effect on 0-width lines.
Setting a pen width with a negative value is not supported.
See also width().
Returns the pen style.
See also setStyle().
Returns the pen width with integer preceision.
See also setWidth().
Returns the pen width with floating point precision.
See also setWidthF().
Returns the pen as a QVariant
Returns true if the pen is different from p; otherwise returns false.
Two pens are different if they have different styles, widths or colors.
See also operator==().
Assigns p to this pen and returns a reference to this pen.
Returns true if the pen is equal to p; otherwise returns false.
Two pens are equal if they have equal styles, widths and colors.
See also operator!=().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Writes the pen p to the stream s and returns a reference to the stream.
See also Format of the QDataStream operators.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Reads a pen from the stream s into p and returns a reference to the stream.
See also Format of the QDataStream operators.
Copyright © 2005 Trolltech | Trademarks | Qt 4.0.0-b2 |