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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QGraphicsEffect Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</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="index.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">QGraphicsEffect Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QGraphicsEffect class is the base class for all graphics
effects. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><p>Inherited by <a href="qgraphicsblureffect.html">QGraphicsBlurEffect</a>, <a href="qgraphicscolorizeeffect.html">QGraphicsColorizeEffect</a>, <a href="qgraphicsdropshadoweffect.html">QGraphicsDropShadowEffect</a> and <a href="qgraphicsopacityeffect.html">QGraphicsOpacityEffect</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qgraphicseffect.html#ChangeFlag-enum">ChangeFlag</a></b> { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated }</li><li><div class="fn" />class <b><a href="qgraphicseffect-changeflags.html">ChangeFlags</a></b></li><li><div class="fn" />enum <b><a href="qgraphicseffect.html#PixmapPadMode-enum">PixmapPadMode</a></b> { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qgraphicseffect.html#QGraphicsEffect">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#boundingRect">boundingRect</a></b> (<i>self</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a></b> (<i>self</i>, QRectF <i>sourceRect</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#draw">draw</a></b> (<i>self</i>, QPainter <i>painter</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#drawSource">drawSource</a></b> (<i>self</i>, QPainter <i>painter</i>)</li><li><div class="fn" />bool <b><a href="qgraphicseffect.html#isEnabled">isEnabled</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#setEnabled">setEnabled</a></b> (<i>self</i>, bool <i>enable</i>)</li><li><div class="fn" />QRectF <b><a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a></b> (<i>self</i>, Qt.CoordinateSystem <i>system</i> = Qt.LogicalCoordinates)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#sourceChanged">sourceChanged</a></b> (<i>self</i>, ChangeFlags <i>flags</i>)</li><li><div class="fn" />bool <b><a href="qgraphicseffect.html#sourceIsPixmap">sourceIsPixmap</a></b> (<i>self</i>)</li><li><div class="fn" />(QPixmap, QPoint <i>offset</i>) <b><a href="qgraphicseffect.html#sourcePixmap">sourcePixmap</a></b> (<i>self</i>, Qt.CoordinateSystem <i>system</i> = Qt.LogicalCoordinates, PixmapPadMode <i>mode</i> = QGraphicsEffect.PadToEffectiveBoundingRect)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#update">update</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qgraphicseffect.html#enabledChanged">enabledChanged</a></b> (bool)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QGraphicsEffect class is the base class for all graphics
effects.</p>
<p>Effects alter the appearance of elements by hooking into the
rendering pipeline and operating between the source (e.g., a
<a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>) and the
destination device (e.g., <a href="qgraphicsview.html">QGraphicsView</a>'s viewport). Effects can be
disabled by calling setEnabled(false). If effects are disabled, the
source is rendered directly.</p>
<p>To add a visual effect to a <a href="qgraphicsitem.html">QGraphicsItem</a>, for example, you can use
one of the standard effects, or alternately, create your own effect
by creating a subclass of QGraphicsEffect. The effect can then be
installed on the item using <a href="qgraphicsitem.html#setGraphicsEffect">QGraphicsItem.setGraphicsEffect</a>().</p>
<p>Qt provides the following standard effects:</p>
<ul>
<li><a href="qgraphicsblureffect.html">QGraphicsBlurEffect</a> -
blurs the item by a given radius</li>
<li><a href="qgraphicsdropshadoweffect.html">QGraphicsDropShadowEffect</a> -
renders a dropshadow behind the item</li>
<li><a href="qgraphicscolorizeeffect.html">QGraphicsColorizeEffect</a> -
renders the item in shades of any given color</li>
<li><a href="qgraphicsopacityeffect.html">QGraphicsOpacityEffect</a> - renders
the item with an opacity</li>
</ul>
<table class="generic">
<tr class="odd" valign="top">
<td colspan="2">
<p class="centerAlign"><img alt="" src="images/graphicseffect-plain.png" /></p>
</td>
</tr>
<tr class="even" valign="top">
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-blur.png" /></p>
</td>
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-colorize.png" /></p>
</td>
</tr>
<tr class="odd" valign="top">
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-opacity.png" /></p>
</td>
<td>
<p class="centerAlign"><img alt="" src="images/graphicseffect-drop-shadow.png" /></p>
</td>
</tr>
</table>
<p class="centerAlign"><img alt="" src="images/graphicseffect-widget.png" /></p>
<p>For more information on how to use each effect, refer to the
specific effect's documentation.</p>
<p>To create your own custom effect, create a subclass of
QGraphicsEffect (or any other existing effects) and reimplement the
virtual function <a href="qgraphicseffect.html#draw">draw</a>().
This function is called whenever the effect needs to redraw. The
<a href="qgraphicseffect.html#draw">draw</a>() function takes the
painter with which to draw as an argument. For more information,
refer to the documenation for <a href="qgraphicseffect.html#draw">draw</a>(). In the <a href="qgraphicseffect.html#draw">draw</a>() function you can call
<a href="qgraphicseffect.html#sourcePixmap">sourcePixmap</a>() to
get a pixmap of the graphics effect source which you can then
process.</p>
<p>If your effect changes, use <a href="qgraphicseffect.html#update">update</a>() to request for a redraw.
If your custom effect changes the bounding rectangle of the source,
e.g., a radial glow effect may need to apply an extra margin, you
can reimplement the virtual <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>()
function, and call <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>()
to notify the framework whenever this rectangle changes. The
virtual <a href="qgraphicseffect.html#sourceChanged">sourceChanged</a>() function
is called to notify the effects that the source has changed in some
way - e.g., if the source is a <a href="qgraphicsrectitem.html">QGraphicsRectItem</a> and its rectangle
parameters have changed.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ChangeFlag-enum" />QGraphicsEffect.ChangeFlag</h3><p>This enum describes what has changed in
QGraphicsEffectSource.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.SourceAttached</tt></td>
<td class="topAlign"><tt>0x1</tt></td>
<td class="topAlign">The effect is installed on a source.</td>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.SourceDetached</tt></td>
<td class="topAlign"><tt>0x2</tt></td>
<td class="topAlign">The effect is uninstalled on a source.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.SourceBoundingRectChanged</tt></td>
<td class="topAlign"><tt>0x4</tt></td>
<td class="topAlign">The bounding rect of the source has
changed.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.SourceInvalidated</tt></td>
<td class="topAlign"><tt>0x8</tt></td>
<td class="topAlign">The visual appearance of the source has
changed.</td>
</tr>
</table>
<p>The ChangeFlags type is a typedef for <a href="qflags.html">QFlags</a><ChangeFlag>. It stores an OR
combination of ChangeFlag values.</p>
<h3 class="fn"><a name="PixmapPadMode-enum" />QGraphicsEffect.PixmapPadMode</h3><p>This enum describes how the pixmap returned from sourcePixmap
should be padded.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QGraphicsEffect.NoPad</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">The pixmap should not receive any additional
padding.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.PadToTransparentBorder</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">The pixmap should be padded to ensure it has a
completely transparent border.</td>
</tr>
<tr>
<td class="topAlign">
<tt>QGraphicsEffect.PadToEffectiveBoundingRect</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">The pixmap should be padded to match the
effective bounding rectangle of the effect.</td>
</tr>
</table>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QGraphicsEffect" />QGraphicsEffect.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new <a href="qgraphicseffect.html">QGraphicsEffect</a> instance having the
specified <i>parent</i>.</p>
<h3 class="fn"><a name="boundingRect" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.boundingRect (<i>self</i>)</h3><p>Returns the effective bounding rectangle for this effect, i.e.,
the bounding rectangle of the source in device coordinates,
adjusted by any margins applied by the effect itself.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>() and
<a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>().</p>
<h3 class="fn"><a name="boundingRectFor" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.boundingRectFor (<i>self</i>, <a href="qrectf.html">QRectF</a> <i>sourceRect</i>)</h3><p>Returns the effective bounding rectangle for this effect, given
the provided <i>rect</i> in the device coordinates. When writing
you own custom effect, you must call <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>()
whenever any parameters are changed that may cause this this
function to return a different value.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a>().</p>
<h3 class="fn"><a name="draw" />QGraphicsEffect.draw (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>This pure virtual function draws the effect and is called
whenever the source needs to be drawn.</p>
<p>Reimplement this function in a <a href="qgraphicseffect.html">QGraphicsEffect</a> subclass to provide the
effect's drawing implementation, using <i>painter</i>.</p>
<p>For example:</p>
<pre class="cpp">
MyGraphicsEffect<span class="operator">.</span>draw(<span class="type"><a href="qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
{
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
<span class="type"><a href="qpoint.html">QPoint</a></span> offset;
<span class="keyword">if</span> (sourceIsPixmap()) {
<span class="comment">// No point in drawing in device coordinates (pixmap will be scaled anyways).</span>
<span class="keyword">const</span> <span class="type"><a href="qpixmap.html">QPixmap</a></span> pixmap <span class="operator">=</span> sourcePixmap(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>LogicalCoordinates<span class="operator">,</span> <span class="operator">&</span>offset);
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
painter<span class="operator">-</span><span class="operator">></span>drawPixmap(offset<span class="operator">,</span> pixmap);
} <span class="keyword">else</span> {
<span class="comment">// Draw pixmap in device coordinates to avoid pixmap scaling;</span>
<span class="keyword">const</span> <span class="type"><a href="qpixmap.html">QPixmap</a></span> pixmap <span class="operator">=</span> sourcePixmap(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">.</span>DeviceCoordinates<span class="operator">,</span> <span class="operator">&</span>offset);
painter<span class="operator">-</span><span class="operator">></span>setWorldTransform(<span class="type"><a href="qtransform.html">QTransform</a></span>());
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
painter<span class="operator">-</span><span class="operator">></span>drawPixmap(offset<span class="operator">,</span> pixmap);
}
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}
</pre>
<p>This function should not be called explicitly by the user, since
it is meant for reimplementation purposes only.</p>
<h3 class="fn"><a name="drawSource" />QGraphicsEffect.drawSource (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>)</h3><p>Draws the source directly using the given <i>painter</i>.</p>
<p>This function should only be called from <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>().</p>
<p>For example:</p>
<pre class="cpp">
MyGraphicsOpacityEffect<span class="operator">.</span><a href="qgraphicseffect.html#draw">draw</a>(<span class="type"><a href="qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
{
<span class="comment">// Fully opaque; draw directly without going through a pixmap.</span>
<span class="keyword">if</span> (<a href="qquaternion.html#qFuzzyCompare">qFuzzyCompare</a>(m_opacity<span class="operator">,</span> <span class="number">1</span>)) {
drawSource(painter);
<span class="keyword">return</span>;
}
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}
</pre>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>().</p>
<h3 class="fn"><a name="isEnabled" />bool QGraphicsEffect.isEnabled (<i>self</i>)</h3><h3 class="fn"><a name="setEnabled" />QGraphicsEffect.setEnabled (<i>self</i>, bool <i>enable</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setEnabled(bool)</tt>.</p><h3 class="fn"><a name="sourceBoundingRect" /><a href="qrectf.html">QRectF</a> QGraphicsEffect.sourceBoundingRect (<i>self</i>, <a href="qt.html#CoordinateSystem-enum">Qt.CoordinateSystem</a> <i>system</i> = Qt.LogicalCoordinates)</h3><p>Returns the bounding rectangle of the source mapped to the given
<i>system</i>.</p>
<p>Calling this function with <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a> outside
of <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>()
will give undefined results, as there is no device context
available.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">draw</a>().</p>
<h3 class="fn"><a name="sourceChanged" />QGraphicsEffect.sourceChanged (<i>self</i>, <a href="qgraphicseffect-changeflags.html">ChangeFlags</a> <i>flags</i>)</h3><p>This virtual function is called by <a href="qgraphicseffect.html">QGraphicsEffect</a> to notify the effect
that the source has changed. If the effect applies any cache, then
this cache must be purged in order to reflect the new appearance of
the source.</p>
<p>The <i>flags</i> describes what has changed.</p>
<h3 class="fn"><a name="sourceIsPixmap" />bool QGraphicsEffect.sourceIsPixmap (<i>self</i>)</h3><p>Returns true if the source effectively is a pixmap, e.g., a
<a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>.</p>
<p>This function is useful for optimization purposes. For instance,
there's no point in drawing the source in device coordinates to
avoid pixmap scaling if this function returns true - the source
pixmap will be scaled anyways.</p>
<h3 class="fn"><a name="sourcePixmap" />(<a href="qpixmap.html">QPixmap</a>, <a href="qpoint.html">QPoint</a> <i>offset</i>) QGraphicsEffect.sourcePixmap (<i>self</i>, <a href="qt.html#CoordinateSystem-enum">Qt.CoordinateSystem</a> <i>system</i> = Qt.LogicalCoordinates, <a href="qgraphicseffect.html#PixmapPadMode-enum">PixmapPadMode</a> <i>mode</i> = QGraphicsEffect.PadToEffectiveBoundingRect)</h3><p>Returns a pixmap with the source painted into it.</p>
<p>The <i>system</i> specifies which coordinate system to be used
for the source. The optional <i>offset</i> parameter returns the
offset where the pixmap should be painted at using the current
painter. For control on how the pixmap is padded use the
<i>mode</i> parameter.</p>
<p>The returned pixmap is clipped to the current painter's device
rectangle when <i>system</i> is <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a>.</p>
<p>Calling this function with <a href="qt.html#CoordinateSystem-enum">Qt.DeviceCoordinates</a> outside
of <a href="qgraphicseffect.html#draw">QGraphicsEffect.draw</a>()
will give undefined results, as there is no device context
available.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#draw">draw</a>()
and <a href="qgraphicseffect.html#boundingRect">boundingRect</a>().</p>
<h3 class="fn"><a name="update" />QGraphicsEffect.update (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void update()</tt>.</p><p>Schedules a redraw of the effect. Call this function whenever
the effect needs to be redrawn. This function does not trigger a
redraw of the source.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#updateBoundingRect">updateBoundingRect</a>().</p>
<h3 class="fn"><a name="updateBoundingRect" />QGraphicsEffect.updateBoundingRect (<i>self</i>)</h3><p>This function notifies the effect framework when the effect's
bounding rectangle has changed. As a custom effect author, you must
call this function whenever you change any parameters that will
cause the virtual <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>()
function to return a different value.</p>
<p>This function will call <a href="qgraphicseffect.html#update">update</a>() if this is
necessary.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#boundingRectFor">boundingRectFor</a>(),
<a href="qgraphicseffect.html#boundingRect">boundingRect</a>(), and
<a href="qgraphicseffect.html#sourceBoundingRect">sourceBoundingRect</a>().</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="enabledChanged" />void enabledChanged (bool)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the effect is enabled or
disabled. The <i>enabled</i> parameter holds the effects's new
enabled state.</p>
<p><b>See also</b> <a href="qgraphicseffect.html#enabled-prop">isEnabled</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.12.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.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt 4.8.7</td></tr></table></div></address></body></html>
|