<class name="QPen" doc="/** <p>The <a href="QPen.html#QPen(com.trolltech.qt.gui.QBrush, double, com.trolltech.qt.core.Qt.PenStyle, com.trolltech.qt.core.Qt.PenCapStyle, com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>QPen</tt></a> class defines how a <a href="QPainter.html"><tt>QPainter</tt></a> should draw lines and outlines of shapes.</p> <p>A pen has a <a href="QPen.html#style()"><tt>style</tt></a>, <a href="QPen.html#width()"><tt>width</tt></a>, <a href="QPen.html#brush()"><tt>brush</tt></a>, <a href="QPen.html#capStyle()"><tt>capStyle</tt></a> and <a href="QPen.html#joinStyle()"><tt>joinStyle</tt></a>.</p> <p>The pen style defines the line type. The brush is used to fill strokes generated with the pen. Use the <a href="QBrush.html"><tt>QBrush</tt></a> class to specify fill styles. The cap style determines the line end caps that can be drawn using <a href="QPainter.html"><tt>QPainter</tt></a>, while the join style describes how joins between two lines are drawn. The pen width can be specified in both integer (<a href="QPen.html#width()"><tt>width</tt></a>) and floating point (<a href="QPen.html#widthF()"><tt>widthF</tt></a>) 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 <a href="QPainter.html#coordinate-transformations">transformation</tt></a> set on the painter.</p> <p>The various settings can easily be modified using the corresponding <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a>, <a href="QPen.html#setWidth(int)"><tt>setWidth</tt></a>, <a href="QPen.html#setBrush(com.trolltech.qt.gui.QBrush)"><tt>setBrush</tt></a>, <a href="QPen.html#setCapStyle(com.trolltech.qt.core.Qt.PenCapStyle)"><tt>setCapStyle</tt></a> and <a href="QPen.html#setJoinStyle(com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>setJoinStyle</tt></a> functions (note that the painter's pen must be reset when altering the pen's properties).</p> <p>For example:</p> <pre> QPainter painter(this); QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin); painter.setPen(pen);</pre> <p>which is equivalent to</p> <pre> QPainter painter(this); QPen pen(); <span class="comment">// creates a default pen</span> pen.setStyle(Qt::DashDotLine); pen.setWidth(3); pen.setBrush(Qt::green); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); painter.setPen(pen);</pre> <p>The default pen is a solid black brush with 0 width, square cap style (Qt::SquareCap), and bevel join style (Qt::BevelJoin).</p> <p>In addition <a href="QPen.html#QPen(com.trolltech.qt.gui.QBrush, double, com.trolltech.qt.core.Qt.PenStyle, com.trolltech.qt.core.Qt.PenCapStyle, com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>QPen</tt></a> provides the <a href="QPen.html#color()"><tt>color</tt></a> and <a href="QPen.html#setColor(com.trolltech.qt.gui.QColor)"><tt>setColor</tt></a> convenience functions to extract and set the color of the pen's brush, respectively. Pens may also be compared and streamed.</p> <p>For more information about painting in general, see <a href="%2E%2E/paintsystem.html">The Paint System</tt></a> documentation.</p> <ul><li><a href="#pen-style">Pen Style</a></li> <li><a href="#cap-style">Cap Style</a></li> <li><a href="#join-style">Join Style</a></li> </ul> <a name="pen-style"></a> <h3>Pen Style</h3> <p>Qt provides several built-in styles represented by the Qt::PenStyle enum:</p> <p><table align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-solid.png" /></td><td><img src="%2E%2E/images/qpen-dash.png" /></td><td><img src="%2E%2E/images/qpen-dot.png" /></td></tr> <tr valign="top" class="even"><td>Qt::SolidLine</td><td>Qt::DashLine</td><td>Qt::DotLine</td></tr> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-dashdot.png" /></td><td><img src="%2E%2E/images/qpen-dashdotdot.png" /></td><td><img src="%2E%2E/images/qpen-custom.png" /></td></tr> <tr valign="top" class="even"><td>Qt::DashDotLine</td><td>Qt::DashDotDotLine</td><td>Qt::CustomDashLine</td></tr> </table></p> <p>Simply use the <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a> 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.</p> <p>Since Qt 4.1 it is also possible to specify a custom dash pattern using the <a href="QPen.html#setDashPattern(java.util.List<java.lang.Double>)"><tt>setDashPattern</tt></a> 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</tt> entries where the entries 1, 3, 5..&#x2e; are the dashes and 2, 4, 6..&#x2e; are the spaces. For example, the custom pattern shown above is created using the following code:</p> <pre> QPen pen; QVector&lt;qreal&gt; dashes; qreal space = 4; dashes &lt;&lt; 1 &lt;&lt; space &lt;&lt; 3 &lt;&lt; space &lt;&lt; 9 &lt;&lt; space &lt;&lt; 27 &lt;&lt; space &lt;&lt; 9; pen.setDashPattern(dashes);</pre> <p>Note that the dash pattern is specified in units of the pens width, e.g&#x2e; a dash of length 5 in width 10 is 50 pixels long.</p> <p>The currently set dash pattern can be retrieved using the <a href="QPen.html#dashPattern()"><tt>dashPattern</tt></a> function. Use the <a href="QPen.html#isSolid()"><tt>isSolid</tt></a> function to determine whether the pen has a solid fill, or not.</p> <a name="cap-style"></a> <h3>Cap Style</h3> <p>The cap style defines how the end points of lines are drawn using <a href="QPainter.html"><tt>QPainter</tt></a>. The cap style only apply to wide lines, i.e&#x2e; when the width is 1 or greater. The Qt::PenCapStyle enum provides the following styles:</p> <p><table align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-square.png" /></td><td><img src="%2E%2E/images/qpen-flat.png" /></td><td><img src="%2E%2E/images/qpen-roundcap.png" /></td></tr> <tr valign="top" class="even"><td>Qt::SquareCap</td><td>Qt::FlatCap</td><td>Qt::RoundCap</td></tr> </table></p> <p>The 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.</p> <p>The default is Qt::SquareCap.</p> <p>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.</p> <a name="join-style"></a> <h3>Join Style</h3> <p>The join style defines how joins between two connected lines can be drawn using <a href="QPainter.html"><tt>QPainter</tt></a>. The join style only apply to wide lines, i.e&#x2e; when the width is 1 or greater. The Qt::PenJoinStyle enum provides the following styles:</p> <p><table align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-bevel.png" /></td><td><img src="%2E%2E/images/qpen-miter.png" /></td><td><img src="%2E%2E/images/qpen-roundjoin.png" /></td></tr> <tr valign="top" class="even"><td>Qt::BevelJoin</td><td>Qt::MiterJoin</td><td>Qt::RoundJoin</td></tr> </table></p> <p>The 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.</p> <p>The default is Qt::BevelJoin.</p> <p align="center"><img src="%2E%2E/images/qpen-miterlimit.png" /></p><p>When the Qt::MiterJoin style is applied, it is possible to use the <a href="QPen.html#setMiterLimit(double)"><tt>setMiterLimit</tt></a> function to specify how far the miter join can extend from the join point. The <a href="QPen.html#miterLimit()"><tt>miterLimit</tt></a> is used to reduce artifacts between line joins where the lines are close to parallel.</p> <p>The <a href="QPen.html#miterLimit()"><tt>miterLimit</tt></a> must be specified in units of the pens width, e.g&#x2e; a miter limit of 5 in width 10 is 50 pixels long. The default miter limit is 2, i.e&#x2e; twice the pen width in pixels.</p> <p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-demo.png" /></td><td><b>The Path Stroking Demo</tt></b><p>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.</p> </td></tr> </table></p> @see <a href="QPainter.html"><tt>QPainter</tt></a> @see <a href="QBrush.html"><tt>QBrush</tt></a> @see Path Stroking Demo</tt> @see Scribble Example</tt> */"> <method name="public QPen(com.trolltech.qt.gui.QPen pen)" doc="/** <p>Constructs a pen that is a copy of the given <tt>pen</tt>.</p> */"/> <method name="public QPen()" doc="/** <p>Constructs a default black solid line pen with 0 width.</p> */"/> <method name="public QPen(com.trolltech.qt.core.Qt.PenStyle arg__1)" doc="/** <p>Constructs a black pen with 0 width and the given <tt>arg__1</tt>.</p> @see <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a> */"/> <method name="public QPen(com.trolltech.qt.gui.QColor color)" doc="/** <p>Constructs a solid line pen with 0 width and the given <tt>color</tt>.</p> @see <a href="QPen.html#setBrush(com.trolltech.qt.gui.QBrush)"><tt>setBrush</tt></a> @see <a href="QPen.html#setColor(com.trolltech.qt.gui.QColor)"><tt>setColor</tt></a> */"/> <method name="public QPen(com.trolltech.qt.gui.QBrush brush, double width, com.trolltech.qt.core.Qt.PenStyle s, com.trolltech.qt.core.Qt.PenCapStyle c, com.trolltech.qt.core.Qt.PenJoinStyle j)" doc="/** <p>Constructs a pen with the specified <tt>brush</tt>, <tt>width</tt>, pen <tt>s</tt>, <tt>c</tt> style and <tt>j</tt> style.</p> @see <a href="QPen.html#setBrush(com.trolltech.qt.gui.QBrush)"><tt>setBrush</tt></a> @see <a href="QPen.html#setWidth(int)"><tt>setWidth</tt></a> @see <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a> @see <a href="QPen.html#setCapStyle(com.trolltech.qt.core.Qt.PenCapStyle)"><tt>setCapStyle</tt></a> @see <a href="QPen.html#setJoinStyle(com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>setJoinStyle</tt></a> */"/> <method name="public QPen(com.trolltech.qt.gui.QBrush brush, double width, com.trolltech.qt.core.Qt.PenStyle s, com.trolltech.qt.core.Qt.PenCapStyle c)" doc="/** <p>Equivalent to <a href="QPen.html#QPen(com.trolltech.qt.gui.QBrush, double, com.trolltech.qt.core.Qt.PenStyle, com.trolltech.qt.core.Qt.PenCapStyle, com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>QPen</tt></a>(<tt>brush</tt>, <tt>width</tt>, <tt>s</tt>, <tt>c</tt>, Qt::BevelJoin). */"/> <method name="public QPen(com.trolltech.qt.gui.QBrush brush, double width, com.trolltech.qt.core.Qt.PenStyle s)" doc="/** <p>Equivalent to <a href="QPen.html#QPen(com.trolltech.qt.gui.QBrush, double, com.trolltech.qt.core.Qt.PenStyle, com.trolltech.qt.core.Qt.PenCapStyle, com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>QPen</tt></a>(<tt>brush</tt>, <tt>width</tt>, <tt>s</tt>, Qt::SquareCap, Qt::BevelJoin). */"/> <method name="public QPen(com.trolltech.qt.gui.QBrush brush, double width)" doc="/** <p>Equivalent to <a href="QPen.html#QPen(com.trolltech.qt.gui.QBrush, double, com.trolltech.qt.core.Qt.PenStyle, com.trolltech.qt.core.Qt.PenCapStyle, com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>QPen</tt></a>(<tt>brush</tt>, <tt>width</tt>, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin). */"/> <method name="public final com.trolltech.qt.gui.QBrush brush()" doc="/** <p>Returns the brush used to fill strokes generated with this pen.</p> @see <a href="QPen.html#setBrush(com.trolltech.qt.gui.QBrush)"><tt>setBrush</tt></a> */"/> <method name="public final com.trolltech.qt.core.Qt.PenCapStyle capStyle()" doc="/** <p>Returns the pen's cap style.</p> @see <a href="QPen.html#setCapStyle(com.trolltech.qt.core.Qt.PenCapStyle)"><tt>setCapStyle</tt></a> @see Cap Style</tt> */"/> <method name="public final com.trolltech.qt.gui.QColor color()" doc="/** <p>Returns the color of this pen's brush.</p> @see <a href="QPen.html#brush()"><tt>brush</tt></a> @see <a href="QPen.html#setColor(com.trolltech.qt.gui.QColor)"><tt>setColor</tt></a> */"/> <method name="public final double dashOffset()" doc="/** <p>Returns the dash offset for the pen.</p> @see <a href="QPen.html#setDashOffset(double)"><tt>setDashOffset</tt></a> */"/> <method name="public final java.util.List<java.lang.Double> dashPattern()" doc="/** <p>Returns the dash pattern of this pen.</p> @see <a href="QPen.html#setDashPattern(java.util.List<java.lang.Double>)"><tt>setDashPattern</tt></a> @see <a href="QPen.html#style()"><tt>style</tt></a> @see <a href="QPen.html#isSolid()"><tt>isSolid</tt></a> */"/> <method name="public final boolean isCosmetic()" doc="/** <p>Returns true if the pen is cosmetic; otherwise returns false.</p> <p>Cosmetic pens are used to draw strokes that have a constant width regardless of any transformations applied to the <a href="QPainter.html"><tt>QPainter</tt></a> they are used with. Drawing a shape with a cosmetic pen ensures that its outline will have the same thickness at different scale factors.</p> <p>A zero width pen is cosmetic by default; pens with a non-zero width are non-cosmetic.</p> @see <a href="QPen.html#setCosmetic(boolean)"><tt>setCosmetic</tt></a> @see <a href="QPen.html#widthF()"><tt>widthF</tt></a> */"/> <method name="public final boolean isSolid()" doc="/** <p>Returns true if the pen has a solid fill, otherwise false.</p> @see <a href="QPen.html#style()"><tt>style</tt></a> @see <a href="QPen.html#dashPattern()"><tt>dashPattern</tt></a> */"/> <method name="public final com.trolltech.qt.core.Qt.PenJoinStyle joinStyle()" doc="/** <p>Returns the pen's join style.</p> @see <a href="QPen.html#setJoinStyle(com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>setJoinStyle</tt></a> @see Join Style</tt> */"/> <method name="public final double miterLimit()" doc="/** <p>Returns the miter limit of the pen. The miter limit is only relevant when the join style is set to Qt::MiterJoin.</p> @see <a href="QPen.html#setMiterLimit(double)"><tt>setMiterLimit</tt></a> @see Join Style</tt> */"/> <method name="public final void writeTo(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void readFrom(com.trolltech.qt.core.QDataStream arg__1)"/> <method name="public final void setBrush(com.trolltech.qt.gui.QBrush brush)" doc="/** <p>Sets the brush used to fill strokes generated with this pen to the given <tt>brush</tt>.</p> @see <a href="QPen.html#brush()"><tt>brush</tt></a> @see <a href="QPen.html#setColor(com.trolltech.qt.gui.QColor)"><tt>setColor</tt></a> */"/> <method name="public final void setCapStyle(com.trolltech.qt.core.Qt.PenCapStyle pcs)" doc="/** <p>Sets the pen's cap style to the given <tt>pcs</tt>. The default value is Qt::SquareCap.</p> @see <a href="QPen.html#capStyle()"><tt>capStyle</tt></a> @see Cap Style</tt> */"/> <method name="public final void setColor(com.trolltech.qt.gui.QColor color)" doc="/** <p>Sets the color of this pen's brush to the given <tt>color</tt>.</p> @see <a href="QPen.html#setBrush(com.trolltech.qt.gui.QBrush)"><tt>setBrush</tt></a> @see <a href="QPen.html#color()"><tt>color</tt></a> */"/> <method name="public final void setCosmetic(boolean cosmetic)" doc="/** <p>Sets this pen to cosmetic or non-cosmetic, depending on the value of <tt>cosmetic</tt>.</p> @see <a href="QPen.html#isCosmetic()"><tt>isCosmetic</tt></a> */"/> <method name="public final void setDashOffset(double doffset)" doc="/** <p>Sets the dash offset for this pen to the given <tt>doffset</tt>. This implicitly converts the style of the pen to Qt::CustomDashLine.</p> @see <a href="QPen.html#dashOffset()"><tt>dashOffset</tt></a> */"/> <method name="public final void setDashPattern(java.util.List<java.lang.Double> pattern)" doc="/** <p>Sets the dash pattern for this pen to the given <tt>pattern</tt>. This implicitly converts the style of the pen to Qt::CustomDashLine.</p> <p>The pattern must be specified as an even number of entries where the entries 1, 3, 5..&#x2e; are the dashes and 2, 4, 6..&#x2e; are the spaces. For example:</p> <p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0"> <tr valign="top" class="odd"><td><img src="%2E%2E/images/qpen-custom.png" /></td><td><pre> QPen pen; QVector&lt;qreal&gt; dashes; qreal space = 4; dashes &lt;&lt; 1 &lt;&lt; space &lt;&lt; 3 &lt;&lt; space &lt;&lt; 9 &lt;&lt; space &lt;&lt; 27 &lt;&lt; space &lt;&lt; 9; pen.setDashPattern(dashes);</pre> </td></tr> </table></p> <p>The dash pattern is specified in units of the pens width, e.g&#x2e; a dash of length 5 in width 10 is 50 pixels long. 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.</p> <p>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.</p> @see <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a> @see <a href="QPen.html#dashPattern()"><tt>dashPattern</tt></a> @see <a href="QPen.html#setCapStyle(com.trolltech.qt.core.Qt.PenCapStyle)"><tt>setCapStyle</tt></a> */"/> <method name="public final void setJoinStyle(com.trolltech.qt.core.Qt.PenJoinStyle pcs)" doc="/** <p>Sets the pen's join style to the given <tt>pcs</tt>. The default value is Qt::BevelJoin.</p> @see <a href="QPen.html#joinStyle()"><tt>joinStyle</tt></a> @see Join Style</tt> */"/> <method name="public final void setMiterLimit(double limit)" doc="/** <p>Sets the miter limit of this pen to the given <tt>limit</tt>.</p> <p align="center"><img src="%2E%2E/images/qpen-miterlimit.png" /></p><p>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.</p> <p>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&#x2e; a miter limit of 5 in width 10 is 50 pixels long. The default miter limit is 2, i.e&#x2e; twice the pen width in pixels.</p> @see <a href="QPen.html#miterLimit()"><tt>miterLimit</tt></a> @see <a href="QPen.html#setJoinStyle(com.trolltech.qt.core.Qt.PenJoinStyle)"><tt>setJoinStyle</tt></a> @see Join Style</tt> */"/> <method name="public final void setStyle(com.trolltech.qt.core.Qt.PenStyle arg__1)" doc="/** <p>Sets the pen style to the given <tt>arg__1</tt>.</p> <p>See the <tt>Qt::PenStyle</tt> documentation for a list of the available styles. Since Qt 4.1 it is also possible to specify a custom dash pattern using the <a href="QPen.html#setDashPattern(java.util.List<java.lang.Double>)"><tt>setDashPattern</tt></a> function which implicitly converts the style of the pen to Qt::CustomDashLine.</p> @see <a href="QPen.html#style()"><tt>style</tt></a> @see Pen Style</tt> */"/> <method name="public final void setWidth(int width)" doc="/** <p>Sets the pen width to the given <tt>width</tt> in pixels with integer precision.</p> <p>A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the <a href="QPainter.html#coordinate-transformations">transformation</tt></a> set on the painter.</p> <p>Setting a pen width with a negative value is not supported.</p> @see <a href="QPen.html#setWidthF(double)"><tt>setWidthF</tt></a> @see <a href="QPen.html#width()"><tt>width</tt></a> */"/> <method name="public final void setWidthF(double width)" doc="/** <p>Sets the pen width to the given <tt>width</tt> in pixels with floating point precision.</p> <p>A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the <a href="QPainter.html#coordinate-transformations">transformation</tt></a> on the painter.</p> <p>Setting a pen width with a negative value is not supported.</p> @see <a href="QPen.html#setWidth(int)"><tt>setWidth</tt></a> @see <a href="QPen.html#widthF()"><tt>widthF</tt></a> */"/> <method name="public final com.trolltech.qt.core.Qt.PenStyle style()" doc="/** <p>Returns the pen style.</p> @see <a href="QPen.html#setStyle(com.trolltech.qt.core.Qt.PenStyle)"><tt>setStyle</tt></a> @see Pen Style</tt> */"/> <method name="public final int width()" doc="/** <p>Returns the pen width with integer precision.</p> @see <a href="QPen.html#setWidth(int)"><tt>setWidth</tt></a> @see <a href="QPen.html#widthF()"><tt>widthF</tt></a> */"/> <method name="public final double widthF()" doc="/** <p>Returns the pen width with floating point precision.</p> @see <a href="QPen.html#setWidthF(double)"><tt>setWidthF</tt></a> @see <a href="QPen.html#width()"><tt>width</tt></a> */"/> </class>