summaryrefslogtreecommitdiffstats
path: root/doc/html/qpen.html
blob: ba18e6e4fee112a05a2cfe4ef8d0dfbe79e10c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qpainter.cpp:3138 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QPen Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPen Class Reference</h1>

<p>The QPen class defines how a QPainter should draw lines and outlines
of shapes.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qpen-h.html">qpen.h</a>&gt;</tt>
<p>Inherits <a href="qt.html">Qt</a>.
<p><a href="qpen-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QPen"><b>QPen</b></a> ()</li>
<li class=fn><a href="#QPen-2"><b>QPen</b></a> ( PenStyle&nbsp;style )</li>
<li class=fn><a href="#QPen-3"><b>QPen</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;color, uint&nbsp;width = 0, PenStyle&nbsp;style = SolidLine )</li>
<li class=fn><a href="#QPen-4"><b>QPen</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;cl, uint&nbsp;w, PenStyle&nbsp;s, PenCapStyle&nbsp;c, PenJoinStyle&nbsp;j )</li>
<li class=fn><a href="#QPen-5"><b>QPen</b></a> ( const&nbsp;QPen&nbsp;&amp;&nbsp;p )</li>
<li class=fn><a href="#~QPen"><b>~QPen</b></a> ()</li>
<li class=fn>QPen &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QPen&nbsp;&amp;&nbsp;p )</li>
<li class=fn>PenStyle <a href="#style"><b>style</b></a> () const</li>
<li class=fn>void <a href="#setStyle"><b>setStyle</b></a> ( PenStyle&nbsp;s )</li>
<li class=fn>uint <a href="#width"><b>width</b></a> () const</li>
<li class=fn>void <a href="#setWidth"><b>setWidth</b></a> ( uint&nbsp;w )</li>
<li class=fn>const QColor &amp; <a href="#color"><b>color</b></a> () const</li>
<li class=fn>void <a href="#setColor"><b>setColor</b></a> ( const&nbsp;QColor&nbsp;&amp;&nbsp;c )</li>
<li class=fn>PenCapStyle <a href="#capStyle"><b>capStyle</b></a> () const</li>
<li class=fn>void <a href="#setCapStyle"><b>setCapStyle</b></a> ( PenCapStyle&nbsp;c )</li>
<li class=fn>PenJoinStyle <a href="#joinStyle"><b>joinStyle</b></a> () const</li>
<li class=fn>void <a href="#setJoinStyle"><b>setJoinStyle</b></a> ( PenJoinStyle&nbsp;j )</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QPen&nbsp;&amp;&nbsp;p ) const</li>
<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QPen&nbsp;&amp;&nbsp;p ) const</li>
</ul>
<h2>Related Functions</h2>
<ul>
<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, const&nbsp;QPen&nbsp;&amp;&nbsp;p )</li>
<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QPen&nbsp;&amp;&nbsp;p )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QPen class defines how a <a href="qpainter.html">QPainter</a> should draw lines and outlines
of shapes.
<p> 



<p> A pen has a style, width, color, cap style and join style.
<p> The pen style defines the line type. The default pen style is <a href="qt.html#PenStyle-enum">Qt::SolidLine</a>. Setting the style to <a href="qt.html#PenStyle-enum">NoPen</a> tells the painter to
not draw lines or outlines.
<p> When drawing 1 pixel wide diagonal lines you can either use a very
fast algorithm (specified by a line width of 0, which is the
default), or a slower but more accurate algorithm (specified by a
line width of 1). 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.
<p> The pen color defines the color of lines and text. The default
line color is black. The <a href="qcolor.html">QColor</a> documentation lists predefined
colors.
<p> 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 (<a href="qpainter.html#drawPolyline">QPainter::drawPolyline</a>()
etc.). The cap and join styles only apply to wide lines, i.e. when
the width is 1 or greater.
<p> Use the <a href="qbrush.html">QBrush</a> class to specify fill styles.
<p> Example:
<pre>
    <a href="qpainter.html">QPainter</a> painter;
    QPen     pen( red, 2 );             // red solid line, 2 pixels wide
    painter.<a href="qpainter.html#begin">begin</a>( &amp;anyPaintDevice );   // paint something
    painter.<a href="qpainter.html#setPen">setPen</a>( pen );              // set the red, wide pen
    painter.<a href="qpainter.html#drawRect">drawRect</a>( 40,30, 200,100 ); // draw a rectangle
    painter.<a href="qpainter.html#setPen">setPen</a>( blue );             // set blue pen, 0 pixel width
    painter.<a href="qpainter.html#drawLine">drawLine</a>( 40,30, 240,130 ); // draw a diagonal in rectangle
    painter.<a href="qpainter.html#end">end</a>();                      // painting done
    </pre>
 
<p> See the <a href="qt.html#PenStyle-enum">Qt::PenStyle</a> enum type for a complete list of pen
styles.
<p> 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. <a href="qpainter.html">QPainter</a> 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.
<p> A pen's <a href="#color">color</a>(), <a href="#width">width</a>(), <a href="#style">style</a>(), <a href="#capStyle">capStyle</a>() and <a href="#joinStyle">joinStyle</a>() can
be set in the constructor or later with <a href="#setColor">setColor</a>(), <a href="#setWidth">setWidth</a>(),
<a href="#setStyle">setStyle</a>(), <a href="#setCapStyle">setCapStyle</a>() and <a href="#setJoinStyle">setJoinStyle</a>(). Pens may also be
compared and streamed.
<p> <center><img src="pen-styles.png" alt="Pen styles"></center> 
<p> <p>See also <a href="qpainter.html">QPainter</a>, <a href="qpainter.html#setPen">QPainter::setPen</a>(), <a href="graphics.html">Graphics Classes</a>, <a href="images.html">Image Processing Classes</a>, and <a href="shared.html">Implicitly and Explicitly Shared Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QPen"></a>QPen::QPen ()
</h3>
Constructs a default black solid line pen with 0 width, which
renders lines 1 pixel wide (fast diagonals).

<h3 class=fn><a name="QPen-2"></a>QPen::QPen ( <a href="qt.html#PenStyle-enum">PenStyle</a>&nbsp;style )
</h3>
Constructs a black pen with 0 width (fast diagonals) and style <em>style</em>.
<p> <p>See also <a href="#setStyle">setStyle</a>().

<h3 class=fn><a name="QPen-3"></a>QPen::QPen ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;color, uint&nbsp;width = 0, <a href="qt.html#PenStyle-enum">PenStyle</a>&nbsp;style = SolidLine )
</h3>
Constructs a pen with the specified <em>color</em>, <em>width</em> and <em>style</em>.
<p> <p>See also <a href="#setWidth">setWidth</a>(), <a href="#setStyle">setStyle</a>(), and <a href="#setColor">setColor</a>().

<h3 class=fn><a name="QPen-4"></a>QPen::QPen ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;cl, uint&nbsp;w, <a href="qt.html#PenStyle-enum">PenStyle</a>&nbsp;s, <a href="qt.html#PenCapStyle-enum">PenCapStyle</a>&nbsp;c, <a href="qt.html#PenJoinStyle-enum">PenJoinStyle</a>&nbsp;j )
</h3>
Constructs a pen with the specified color <em>cl</em> and width <em>w</em>.
The pen style is set to <em>s</em>, the pen cap style to <em>c</em> and the
pen join style to <em>j</em>.
<p> 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.
<p> <p>See also <a href="#setWidth">setWidth</a>(), <a href="#setStyle">setStyle</a>(), and <a href="#setColor">setColor</a>().

<h3 class=fn><a name="QPen-5"></a>QPen::QPen ( const&nbsp;<a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p )
</h3>
Constructs a pen that is a copy of <em>p</em>.

<h3 class=fn><a name="~QPen"></a>QPen::~QPen ()
</h3>
Destroys the pen.

<h3 class=fn><a href="qt.html#PenCapStyle-enum">PenCapStyle</a> <a name="capStyle"></a>QPen::capStyle () const
</h3>
Returns the pen's cap style.
<p> <p>See also <a href="#setCapStyle">setCapStyle</a>().

<h3 class=fn>const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp; <a name="color"></a>QPen::color () const
</h3>

<p> Returns the pen color.
<p> <p>See also <a href="#setColor">setColor</a>().

<p>Example: <a href="scribble-example.html#x902">scribble/scribble.h</a>.
<h3 class=fn><a href="qt.html#PenJoinStyle-enum">PenJoinStyle</a> <a name="joinStyle"></a>QPen::joinStyle () const
</h3>
Returns the pen's join style.
<p> <p>See also <a href="#setJoinStyle">setJoinStyle</a>().

<h3 class=fn>bool <a name="operator!-eq"></a>QPen::operator!= ( const&nbsp;<a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p ) const
</h3>

<p> Returns TRUE if the pen is different from <em>p</em>; otherwise returns
FALSE.
<p> Two pens are different if they have different styles, widths or
colors.
<p> <p>See also <a href="#operator-eq-eq">operator==</a>().

<h3 class=fn><a href="qpen.html">QPen</a>&nbsp;&amp; <a name="operator-eq"></a>QPen::operator= ( const&nbsp;<a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p )
</h3>
Assigns <em>p</em> to this pen and returns a reference to this pen.

<h3 class=fn>bool <a name="operator-eq-eq"></a>QPen::operator== ( const&nbsp;<a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p ) const
</h3>
Returns TRUE if the pen is equal to <em>p</em>; otherwise returns FALSE.
<p> Two pens are equal if they have equal styles, widths and colors.
<p> <p>See also <a href="#operator!-eq">operator!=</a>().

<h3 class=fn>void <a name="setCapStyle"></a>QPen::setCapStyle ( <a href="qt.html#PenCapStyle-enum">PenCapStyle</a>&nbsp;c )
</h3>
Sets the pen's cap style to <em>c</em>.
<p> The default value is <a href="qt.html#PenCapStyle-enum">FlatCap</a>. The cap style has no effect on
0-width pens.
<p> <center><img src="pen-cap-styles.png" alt="Pen Cap Styles"></center> 
<p> <b>Warning:</b> On Windows 95/98 and Macintosh, the cap style setting has
no effect. Wide lines are rendered as if the cap style was <a href="qt.html#PenCapStyle-enum">SquareCap</a>.
<p> <p>See also <a href="#capStyle">capStyle</a>().

<p>Example: <a href="themes-example.html#x226">themes/wood.cpp</a>.
<h3 class=fn>void <a name="setColor"></a>QPen::setColor ( const&nbsp;<a href="qcolor.html">QColor</a>&nbsp;&amp;&nbsp;c )
</h3>
Sets the pen color to <em>c</em>.
<p> <p>See also <a href="#color">color</a>().

<p>Examples: <a href="progress-example.html#x79">progress/progress.cpp</a> and <a href="scribble-example.html#x903">scribble/scribble.h</a>.
<h3 class=fn>void <a name="setJoinStyle"></a>QPen::setJoinStyle ( <a href="qt.html#PenJoinStyle-enum">PenJoinStyle</a>&nbsp;j )
</h3>
Sets the pen's join style to <em>j</em>.
<p> The default value is <a href="qt.html#PenJoinStyle-enum">MiterJoin</a>. The join style has no effect on
0-width pens.
<p> <center><img src="pen-join-styles.png" alt="Pen Join Styles"></center> 
<p> <b>Warning:</b> On Windows 95/98 and Macintosh, the join style setting
has no effect. Wide lines are rendered as if the join style was <a href="qt.html#PenJoinStyle-enum">BevelJoin</a>.
<p> <p>See also <a href="#joinStyle">joinStyle</a>().

<p>Example: <a href="themes-example.html#x227">themes/wood.cpp</a>.
<h3 class=fn>void <a name="setStyle"></a>QPen::setStyle ( <a href="qt.html#PenStyle-enum">PenStyle</a>&nbsp;s )
</h3>
Sets the pen style to <em>s</em>.
<p> See the <a href="qt.html#PenStyle-enum">Qt::PenStyle</a> documentation for a list of all the
styles.
<p> <b>Warning:</b> On Mac OS X the style setting (other than <a href="qt.html#PenStyle-enum">NoPen</a> and <a href="qt.html#PenStyle-enum">SolidLine</a>) have no effect as they are not implemented by the
underlying system.
<p> <b>Warning:</b> On Windows 95/98, the style setting (other than <a href="qt.html#PenStyle-enum">NoPen</a>
and <a href="qt.html#PenStyle-enum">SolidLine</a>) has no effect for lines with width greater than
1.
<p> <p>See also <a href="#style">style</a>().

<p>Example: <a href="tutorial2-06.html#x2575">chart/chartform_canvas.cpp</a>.
<h3 class=fn>void <a name="setWidth"></a>QPen::setWidth ( uint&nbsp;w )
</h3>
Sets the pen width to <em>w</em>.
<p> 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.
<p> <p>See also <a href="#width">width</a>().

<p>Examples: <a href="qaxserver-example-multiple.html#x2548">multiple/ax2.h</a>, <a href="progress-example.html#x80">progress/progress.cpp</a>, and <a href="scribble-example.html#x904">scribble/scribble.h</a>.
<h3 class=fn><a href="qt.html#PenStyle-enum">PenStyle</a> <a name="style"></a>QPen::style () const
</h3>

<p> Returns the pen style.
<p> <p>See also <a href="#setStyle">setStyle</a>().

<h3 class=fn>uint <a name="width"></a>QPen::width () const
</h3>

<p> Returns the pen width.
<p> <p>See also <a href="#setWidth">setWidth</a>().

<p>Example: <a href="scribble-example.html#x905">scribble/scribble.h</a>.
<hr><h2>Related Functions</h2>
<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, const&nbsp;<a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p )
</h3>

<p> Writes the pen <em>p</em> to the stream <em>s</em> and returns a reference to
the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qpen.html">QPen</a>&nbsp;&amp;&nbsp;p )
</h3>

<p> Reads a pen from the stream <em>s</em> into <em>p</em> and returns a reference
to the stream.
<p> <p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>