1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
3
<html><head><title>QStaticText Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
4
a:link { color: #004faf; text-decoration: none }
5
a:visited { color: #672967; text-decoration: none }
6
td.postheader { font-family: sans-serif }
7
tr.address { font-family: sans-serif }
8
body { background: #ffffff; color: black; }
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QStaticText Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStaticText class enables optimized drawing of text when the
10
text and its layout is updated rarely. <a href="#details">More...</a></p>
12
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qstatictext.html#PerformanceHint-enum">PerformanceHint</a></b> { ModerateCaching, AggressiveCaching }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstatictext.html#QStaticText">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#QStaticText-2">__init__</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#QStaticText-3">__init__</a></b> (<i>self</i>, QStaticText <i>other</i>)</li><li><div class="fn" />PerformanceHint <b><a href="qstatictext.html#performanceHint">performanceHint</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#prepare">prepare</a></b> (<i>self</i>, QTransform <i>matrix</i> = QTransform(), QFont <i>font</i> = QFont())</li><li><div class="fn" /><b><a href="qstatictext.html#setPerformanceHint">setPerformanceHint</a></b> (<i>self</i>, PerformanceHint <i>performanceHint</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#setText">setText</a></b> (<i>self</i>, QString <i>text</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#setTextFormat">setTextFormat</a></b> (<i>self</i>, Qt.TextFormat <i>textFormat</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#setTextOption">setTextOption</a></b> (<i>self</i>, QTextOption <i>textOption</i>)</li><li><div class="fn" /><b><a href="qstatictext.html#setTextWidth">setTextWidth</a></b> (<i>self</i>, float <i>textWidth</i>)</li><li><div class="fn" />QSizeF <b><a href="qstatictext.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qstatictext.html#text">text</a></b> (<i>self</i>)</li><li><div class="fn" />Qt.TextFormat <b><a href="qstatictext.html#textFormat">textFormat</a></b> (<i>self</i>)</li><li><div class="fn" />QTextOption <b><a href="qstatictext.html#textOption">textOption</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qstatictext.html#textWidth">textWidth</a></b> (<i>self</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qstatictext.html#__eq__">__eq__</a></b> (<i>self</i>, QStaticText)</li><li><div class="fn" />bool <b><a href="qstatictext.html#__ne__">__ne__</a></b> (<i>self</i>, QStaticText)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStaticText class enables optimized drawing of text when the
13
text and its layout is updated rarely.</p>
14
<p>QStaticText provides a way to cache layout data for a block of
15
text so that it can be drawn more efficiently than by using
16
<a href="qpainter.html#drawText">QPainter.drawText</a>() in which
17
the layout information is recalculated with every call.</p>
18
<p>The class primarily provides an optimization for cases where the
19
text, its font and the transformations on the painter are static
20
over several paint events. If the text or its layout is changed for
21
every iteration, <a href="qpainter.html#drawText">QPainter.drawText</a>() is the more
22
efficient alternative, since the static text's layout would have to
23
be recalculated to take the new state into consideration.</p>
24
<p>Translating the painter will not cause the layout of the text to
25
be recalculated, but will cause a very small performance impact on
26
drawStaticText(). Altering any other parts of the painter's
27
transformation or the painter's font will cause the layout of the
28
static text to be recalculated. This should be avoided as often as
29
possible to maximize the performance benefit of using
31
<p>In addition, only affine transformations are supported by
32
drawStaticText(). Calling drawStaticText() on a projected painter
33
will perform slightly worse than using the regular drawText() call,
34
so this should be avoided.</p>
35
<pre class="highlightedCode brush: cpp">
36
class MyWidget: public QWidget
39
MyWidget(QWidget *parent = 0) : QWidget(parent), m_staticText("This is static text")
42
void paintEvent(QPaintEvent *)
44
QPainter painter(this);
45
painter.drawStaticText(0, 0, m_staticText);
49
QStaticText m_staticText;
52
<p>The QStaticText class can be used to mimic the behavior of
53
<a href="qpainter.html#drawText">QPainter.drawText</a>() to a
54
specific point with no boundaries, and also when <a href="qpainter.html#drawText">QPainter.drawText</a>() is called with a
55
bounding rectangle.</p>
56
<p>If a bounding rectangle is not required, create a QStaticText
57
object without setting a preferred text width. The text will then
58
occupy a single line.</p>
59
<p>If you set a text width on the QStaticText object, this will
60
bound the text. The text will be formatted so that no line exceeds
61
the given width. The text width set for QStaticText will not
62
automatically be used for clipping. To achieve clipping in addition
63
to line breaks, use <a href="qpainter.html#setClipRect">QPainter.setClipRect</a>(). The
64
position of the text is decided by the argument passed to <a href="qpainter.html#drawStaticText">QPainter.drawStaticText</a>() and
65
can change from call to call with a minimal impact on
67
<p>QStaticText will attempt to guess the format of the input text
68
using <a href="qt.html#mightBeRichText">Qt.mightBeRichText</a>().
69
To force QStaticText to display its contents as either plain text
70
or rich text, use the function <a href="qstatictext.html#setTextFormat">QStaticText.setTextFormat</a>()
71
and pass in, respectively, <a href="qt.html#TextFormat-enum">Qt.PlainText</a> and <a href="qt.html#TextFormat-enum">Qt.RichText</a>.</p>
72
<p>If it's the first time the static text is drawn, or if the
73
static text, or the painter's font has been altered since the last
74
time it was drawn, the text's layout has to be recalculated. On
75
some paint engines, changing the matrix of the painter will also
76
cause the layout to be recalculated. In particular, this will
77
happen for any engine except for the OpenGL2 paint engine.
78
Recalculating the layout will impose an overhead on the <a href="qpainter.html#drawStaticText">QPainter.drawStaticText</a>() call
79
where it occurs. To avoid this overhead in the paint event, you can
80
call <a href="qstatictext.html#prepare">prepare</a>() ahead of time
81
to ensure that the layout is calculated.</p>
82
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="PerformanceHint-enum" />QStaticText.PerformanceHint</h3><p>This enum the different performance hints that can be set on the
83
<a href="qstatictext.html">QStaticText</a>. These hints can be used
84
to indicate that the <a href="qstatictext.html">QStaticText</a>
85
should use additional caches, if possible, to improve performance
86
at the expense of memory. In particular, setting the performance
87
hint AggressiveCaching on the <a href="qstatictext.html">QStaticText</a> will improve performance when
88
using the OpenGL graphics system or when drawing to a <a href="qglwidget.html">QGLWidget</a>.</p>
89
<table class="valuelist">
94
<th class="tblConst">Constant</th>
95
<th class="tblval">Value</th>
96
<th class="tbldscr">Description</th>
99
<td class="topAlign"><tt>QStaticText.ModerateCaching</tt></td>
100
<td class=" topAlign"><tt>0</tt></td>
101
<td class="topAlign">Do basic caching for high performance at a low
105
<td class="topAlign"><tt>QStaticText.AggressiveCaching</tt></td>
106
<td class=" topAlign"><tt>1</tt></td>
107
<td class="topAlign">Use additional caching when available. This
108
may improve performance at a higher memory cost.</td>
111
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStaticText" />QStaticText.__init__ (<i>self</i>)</h3><p>Constructs an empty <a href="qstatictext.html">QStaticText</a></p>
114
<h3 class="fn"><a name="QStaticText-2" />QStaticText.__init__ (<i>self</i>, QString <i>text</i>)</h3><p>Constructs a <a href="qstatictext.html">QStaticText</a> object
115
with the given <i>text</i>.</p>
118
<h3 class="fn"><a name="QStaticText-3" />QStaticText.__init__ (<i>self</i>, <a href="qstatictext.html">QStaticText</a> <i>other</i>)</h3><p>Constructs a <a href="qstatictext.html">QStaticText</a> object
119
which is a copy of <i>other</i>.</p>
122
<h3 class="fn"><a name="performanceHint" /><a href="qstatictext.html#PerformanceHint-enum">PerformanceHint</a> QStaticText.performanceHint (<i>self</i>)</h3><p>Returns which performance hint is set for the <a href="qstatictext.html">QStaticText</a>.</p>
123
<p>See also <a href="qstatictext.html#setPerformanceHint">setPerformanceHint</a>().</p>
126
<h3 class="fn"><a name="prepare" />QStaticText.prepare (<i>self</i>, <a href="qtransform.html">QTransform</a> <i>matrix</i> = QTransform(), <a href="qfont.html">QFont</a> <i>font</i> = QFont())</h3><p>Prepares the <a href="qstatictext.html">QStaticText</a> object
127
for being painted with the given <i>matrix</i> and the given
128
<i>font</i> to avoid overhead when the actual drawStaticText() call
130
<p>When drawStaticText() is called, the layout of the <a href="qstatictext.html">QStaticText</a> will be recalculated if any part
131
of the <a href="qstatictext.html">QStaticText</a> object has
132
changed since the last time it was drawn. It will also be
133
recalculated if the painter's font is not the same as when the
134
<a href="qstatictext.html">QStaticText</a> was last drawn, or, on
135
any other paint engine than the OpenGL2 engine, if the painter's
136
matrix has been altered since the static text was last drawn.</p>
137
<p>To avoid the overhead of creating the layout the first time you
138
draw the <a href="qstatictext.html">QStaticText</a> after making
139
changes, you can use the prepare() function and pass in the
140
<i>matrix</i> and <i>font</i> you expect to use when drawing the
142
<p>See also <a href="qpainter.html#setFont">QPainter.setFont</a>()
143
and <a class="obsolete" href="qpainter.html#setMatrix">QPainter.setMatrix</a>().</p>
146
<h3 class="fn"><a name="setPerformanceHint" />QStaticText.setPerformanceHint (<i>self</i>, <a href="qstatictext.html#PerformanceHint-enum">PerformanceHint</a> <i>performanceHint</i>)</h3><p>Sets the performance hint of the <a href="qstatictext.html">QStaticText</a> according to the
147
<i>performanceHint</i> provided. The <i>performanceHint</i> is used
148
to customize how much caching is done internally to improve
150
<p>The default is <a href="qstatictext.html#PerformanceHint-enum">QStaticText.ModerateCaching</a>.</p>
151
<p><b>Note:</b> This function will cause the layout of the text to
152
require recalculation.</p>
153
<p>See also <a href="qstatictext.html#performanceHint">performanceHint</a>().</p>
156
<h3 class="fn"><a name="setText" />QStaticText.setText (<i>self</i>, QString <i>text</i>)</h3><p>Sets the text of the <a href="qstatictext.html">QStaticText</a>
158
<p><b>Note:</b> This function will cause the layout of the text to
159
require recalculation.</p>
160
<p>See also <a href="qstatictext.html#text">text</a>().</p>
163
<h3 class="fn"><a name="setTextFormat" />QStaticText.setTextFormat (<i>self</i>, <a href="qt.html#TextFormat-enum">Qt.TextFormat</a> <i>textFormat</i>)</h3><p>Sets the text format of the <a href="qstatictext.html">QStaticText</a> to <i>textFormat</i>. If
164
<i>textFormat</i> is set to <a href="qt.html#TextFormat-enum">Qt.AutoText</a> (the default), the
165
format of the text will try to be determined using the function
166
<a href="qt.html#mightBeRichText">Qt.mightBeRichText</a>(). If the
167
text format is <a href="qt.html#TextFormat-enum">Qt.PlainText</a>,
168
then the text will be displayed as is, whereas it will be
169
interpreted as HTML if the format is <a href="qt.html#TextFormat-enum">Qt.RichText</a>. HTML tags that alter
170
the font of the text, its color, or its layout are supported by
171
<a href="qstatictext.html">QStaticText</a>.</p>
172
<p><b>Note:</b> This function will cause the layout of the text to
173
require recalculation.</p>
174
<p>See also <a href="qstatictext.html#textFormat">textFormat</a>(),
175
<a href="qstatictext.html#setText">setText</a>(), and <a href="qstatictext.html#text">text</a>().</p>
178
<h3 class="fn"><a name="setTextOption" />QStaticText.setTextOption (<i>self</i>, <a href="qtextoption.html">QTextOption</a> <i>textOption</i>)</h3><p>Sets the text option structure that controls the layout process
179
to the given <i>textOption</i>.</p>
180
<p>See also <a href="qstatictext.html#textOption">textOption</a>().</p>
183
<h3 class="fn"><a name="setTextWidth" />QStaticText.setTextWidth (<i>self</i>, float <i>textWidth</i>)</h3><p>Sets the preferred width for this <a href="qstatictext.html">QStaticText</a>. If the text is wider than the
184
specified width, it will be broken into multiple lines and grow
185
vertically. If the text cannot be split into multiple lines, it
186
will be larger than the specified <i>textWidth</i>.</p>
187
<p>Setting the preferred text width to a negative number will cause
188
the text to be unbounded.</p>
189
<p>Use <a href="qstatictext.html#size">size</a>() to get the actual
190
size of the text.</p>
191
<p><b>Note:</b> This function will cause the layout of the text to
192
require recalculation.</p>
193
<p>See also <a href="qstatictext.html#textWidth">textWidth</a>()
194
and <a href="qstatictext.html#size">size</a>().</p>
197
<h3 class="fn"><a name="size" /><a href="qsizef.html">QSizeF</a> QStaticText.size (<i>self</i>)</h3><p>Returns the size of the bounding rect for this <a href="qstatictext.html">QStaticText</a>.</p>
198
<p>See also <a href="qstatictext.html#textWidth">textWidth</a>().</p>
201
<h3 class="fn"><a name="text" />QString QStaticText.text (<i>self</i>)</h3><p>Returns the text of the <a href="qstatictext.html">QStaticText</a>.</p>
202
<p>See also <a href="qstatictext.html#setText">setText</a>().</p>
205
<h3 class="fn"><a name="textFormat" /><a href="qt.html#TextFormat-enum">Qt.TextFormat</a> QStaticText.textFormat (<i>self</i>)</h3><p>Returns the text format of the <a href="qstatictext.html">QStaticText</a>.</p>
206
<p>See also <a href="qstatictext.html#setTextFormat">setTextFormat</a>(), <a href="qstatictext.html#setText">setText</a>(), and <a href="qstatictext.html#text">text</a>().</p>
209
<h3 class="fn"><a name="textOption" /><a href="qtextoption.html">QTextOption</a> QStaticText.textOption (<i>self</i>)</h3><p>Returns the current text option used to control the layout
211
<p>See also <a href="qstatictext.html#setTextOption">setTextOption</a>().</p>
214
<h3 class="fn"><a name="textWidth" />float QStaticText.textWidth (<i>self</i>)</h3><p>Returns the preferred width for this <a href="qstatictext.html">QStaticText</a>.</p>
215
<p>See also <a href="qstatictext.html#setTextWidth">setTextWidth</a>().</p>
218
<h3 class="fn"><a name="__eq__" />bool QStaticText.__eq__ (<i>self</i>, <a href="qstatictext.html">QStaticText</a>)</h3><h3 class="fn"><a name="__ne__" />bool QStaticText.__ne__ (<i>self</i>, <a href="qstatictext.html">QStaticText</a>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.8.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.7.0</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'