<?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>QStylePainter 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">QStylePainter Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStylePainter class is a convenience class for drawing <a href="qstyle.html">QStyle</a> elements inside a widget. <a href="#details">More...</a></p> <p>Inherits <a href="qpainter.html">QPainter</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter-2">__init__</a></b> (<i>self</i>, QWidget <i>w</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#QStylePainter-3">__init__</a></b> (<i>self</i>, QPaintDevice <i>pd</i>, QWidget <i>w</i>)</li><li><div class="fn" />bool <b><a href="qstylepainter.html#begin">begin</a></b> (<i>self</i>, QWidget <i>w</i>)</li><li><div class="fn" />bool <b><a href="qstylepainter.html#begin-2">begin</a></b> (<i>self</i>, QPaintDevice <i>pd</i>, QWidget <i>w</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawComplexControl">drawComplexControl</a></b> (<i>self</i>, QStyle.ComplexControl <i>cc</i>, QStyleOptionComplex <i>opt</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawControl">drawControl</a></b> (<i>self</i>, QStyle.ControlElement <i>ce</i>, QStyleOption <i>opt</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawItemPixmap">drawItemPixmap</a></b> (<i>self</i>, QRect <i>r</i>, int <i>flags</i>, QPixmap <i>pixmap</i>)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawItemText">drawItemText</a></b> (<i>self</i>, QRect <i>rect</i>, int <i>flags</i>, QPalette <i>pal</i>, bool <i>enabled</i>, QString <i>text</i>, QPalette.ColorRole <i>textRole</i> = QPalette.NoRole)</li><li><div class="fn" /><b><a href="qstylepainter.html#drawPrimitive">drawPrimitive</a></b> (<i>self</i>, QStyle.PrimitiveElement <i>pe</i>, QStyleOption <i>opt</i>)</li><li><div class="fn" />QStyle <b><a href="qstylepainter.html#style">style</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStylePainter class is a convenience class for drawing <a href="qstyle.html">QStyle</a> elements inside a widget.</p> <p>QStylePainter extends <a href="qpainter.html">QPainter</a> with a set of high-level <tt>draw...()</tt> functions implemented on top of <a href="qstyle.html">QStyle</a>'s API. The advantage of using QStylePainter is that the parameter lists get considerably shorter. Whereas a <a href="qstyle.html">QStyle</a> object must be able to draw on any widget using any painter (because the application normally has one <a href="qstyle.html">QStyle</a> object shared by all widget), a QStylePainter is initialized with a widget, eliminating the need to specify the <a href="qwidget.html">QWidget</a>, the <a href="qpainter.html">QPainter</a>, and the <a href="qstyle.html">QStyle</a> for every function call.</p> <p>Example using <a href="qstyle.html">QStyle</a> directly:</p> <pre class="cpp"> <span class="type">void</span> MyWidget<span class="operator">.</span>paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span> <span class="comment">/* event */</span>) { <span class="type"><a href="qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>); <span class="type"><a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a></span> option; option<span class="operator">.</span>initFrom(<span class="keyword">this</span>); option<span class="operator">.</span>backgroundColor <span class="operator">=</span> palette()<span class="operator">.</span>color(<span class="type"><a href="qpalette.html">QPalette</a></span><span class="operator">.</span>Background); style()<span class="operator">-</span><span class="operator">></span>drawPrimitive(<span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">.</span>PE_FrameFocusRect<span class="operator">,</span> <span class="operator">&</span>option<span class="operator">,</span> <span class="operator">&</span>painter<span class="operator">,</span> <span class="keyword">this</span>); } </pre> <p>Example using QStylePainter:</p> <pre class="cpp"> <span class="type">void</span> MyWidget<span class="operator">.</span>paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span> <span class="comment">/* event */</span>) { <span class="type">QStylePainter</span> painter(<span class="keyword">this</span>); <span class="type"><a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a></span> option; option<span class="operator">.</span>initFrom(<span class="keyword">this</span>); option<span class="operator">.</span>backgroundColor <span class="operator">=</span> palette()<span class="operator">.</span>color(<span class="type"><a href="qpalette.html">QPalette</a></span><span class="operator">.</span>Background); painter<span class="operator">.</span>drawPrimitive(<span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">.</span>PE_FrameFocusRect<span class="operator">,</span> option); } </pre><hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStylePainter" />QStylePainter.__init__ (<i>self</i>)</h3><p>Constructs a <a href="qstylepainter.html">QStylePainter</a>.</p> <h3 class="fn"><a name="QStylePainter-2" />QStylePainter.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>Construct a <a href="qstylepainter.html">QStylePainter</a> using widget <i>widget</i> for its paint device.</p> <h3 class="fn"><a name="QStylePainter-3" />QStylePainter.__init__ (<i>self</i>, <a href="qpaintdevice.html">QPaintDevice</a> <i>pd</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>Construct a <a href="qstylepainter.html">QStylePainter</a> using <i>pd</i> for its paint device, and attributes from <i>widget</i>.</p> <h3 class="fn"><a name="begin" />bool QStylePainter.begin (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>Begin painting operations on the specified <i>widget</i>. Returns true if the painter is ready to use; otherwise returns false.</p> <p>This is automatically called by the constructor that takes a <a href="qwidget.html">QWidget</a>.</p> <h3 class="fn"><a name="begin-2" />bool QStylePainter.begin (<i>self</i>, <a href="qpaintdevice.html">QPaintDevice</a> <i>pd</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>This is an overloaded function.</p> <p>Begin painting operations on paint device <i>pd</i> as if it was <i>widget</i>.</p> <p>This is automatically called by the constructor that takes a <a href="qpaintdevice.html">QPaintDevice</a> and a <a href="qwidget.html">QWidget</a>.</p> <h3 class="fn"><a name="drawComplexControl" />QStylePainter.drawComplexControl (<i>self</i>, <a href="qstyle.html#ComplexControl-enum">QStyle.ComplexControl</a> <i>cc</i>, <a href="qstyleoptioncomplex.html">QStyleOptionComplex</a> <i>opt</i>)</h3><p>Use the widget's style to draw a complex control <i>cc</i> specified by the <a href="qstyleoptioncomplex.html">QStyleOptionComplex</a> <i>option</i>.</p> <p><b>See also</b> <a href="qstyle.html#drawComplexControl">QStyle.drawComplexControl</a>().</p> <h3 class="fn"><a name="drawControl" />QStylePainter.drawControl (<i>self</i>, <a href="qstyle.html#ControlElement-enum">QStyle.ControlElement</a> <i>ce</i>, <a href="qstyleoption.html">QStyleOption</a> <i>opt</i>)</h3><p>Use the widget's style to draw a control element <i>ce</i> specified by <a href="qstyleoption.html">QStyleOption</a> <i>option</i>.</p> <p><b>See also</b> <a href="qstyle.html#drawControl">QStyle.drawControl</a>().</p> <h3 class="fn"><a name="drawItemPixmap" />QStylePainter.drawItemPixmap (<i>self</i>, <a href="qrect.html">QRect</a> <i>r</i>, int <i>flags</i>, <a href="qpixmap.html">QPixmap</a> <i>pixmap</i>)</h3><p>Draws the <i>pixmap</i> in rectangle <i>rect</i>. The pixmap is aligned according to <i>flags</i>.</p> <p><b>See also</b> <a href="qstyle.html#drawItemPixmap">QStyle.drawItemPixmap</a>() and <a href="qt.html#AlignmentFlag-enum">Qt.Alignment</a>.</p> <h3 class="fn"><a name="drawItemText" />QStylePainter.drawItemText (<i>self</i>, <a href="qrect.html">QRect</a> <i>rect</i>, int <i>flags</i>, <a href="qpalette.html">QPalette</a> <i>pal</i>, bool <i>enabled</i>, QString <i>text</i>, <a href="qpalette.html#ColorRole-enum">QPalette.ColorRole</a> <i>textRole</i> = QPalette.NoRole)</h3><p>Draws the <i>text</i> in rectangle <i>rect</i> and palette <i>pal</i>. The text is aligned and wrapped according to <i>flags</i>.</p> <p>The pen color is specified with <i>textRole</i>. The <i>enabled</i> bool indicates whether or not the item is enabled; when reimplementing this bool should influence how the item is drawn.</p> <p><b>See also</b> <a href="qstyle.html#drawItemText">QStyle.drawItemText</a>() and <a href="qt.html#AlignmentFlag-enum">Qt.Alignment</a>.</p> <h3 class="fn"><a name="drawPrimitive" />QStylePainter.drawPrimitive (<i>self</i>, <a href="qstyle.html#PrimitiveElement-enum">QStyle.PrimitiveElement</a> <i>pe</i>, <a href="qstyleoption.html">QStyleOption</a> <i>opt</i>)</h3><p>Use the widget's style to draw a primitive element <i>pe</i> specified by <a href="qstyleoption.html">QStyleOption</a> <i>option</i>.</p> <p><b>See also</b> <a href="qstyle.html#drawPrimitive">QStyle.drawPrimitive</a>().</p> <h3 class="fn"><a name="style" /><a href="qstyle.html">QStyle</a> QStylePainter.style (<i>self</i>)</h3><p>Return the current style used by the <a href="qstylepainter.html">QStylePainter</a>.</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 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> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>