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
|
<?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>QStyleOption 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="../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">QStyleOption Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStyleOption class stores the parameters used by <a href="qstyle.html">QStyle</a> functions. <a href="#details">More...</a></p>
<p>Inherited by <a href="qstyleoptionbutton.html">QStyleOptionButton</a>, <a href="qstyleoptioncomplex.html">QStyleOptionComplex</a>, <a href="qstyleoptiondockwidget.html">QStyleOptionDockWidget</a>, <a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a>, <a href="qstyleoptionframe.html">QStyleOptionFrame</a>, <a href="qstyleoptionheader.html">QStyleOptionHeader</a>, <a href="qstyleoptionmenuitem.html">QStyleOptionMenuItem</a>, <a href="qstyleoptionprogressbar.html">QStyleOptionProgressBar</a>, <a href="qstyleoptionrubberband.html">QStyleOptionRubberBand</a>, <a href="qstyleoptiontab.html">QStyleOptionTab</a>, <a href="qstyleoptiontabbarbase.html">QStyleOptionTabBarBase</a>, <a href="qstyleoptiontabwidgetframe.html">QStyleOptionTabWidgetFrame</a>, <a href="qstyleoptiontoolbar.html">QStyleOptionToolBar</a>, <a href="qstyleoptiontoolbox.html">QStyleOptionToolBox</a> and <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qstyleoption.html#OptionType-enum">OptionType</a></b> { SO_Default, SO_FocusRect, SO_Button, SO_Tab, ..., SO_ComplexCustomBase }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstyleoption.html#QStyleOption">__init__</a></b> (<i>self</i>, int <i>version</i> = QStyleOption.Version, int <i>type</i> = QStyleOption.SO_Default)</li><li><div class="fn" /><b><a href="qstyleoption.html#QStyleOption-2">__init__</a></b> (<i>self</i>, QStyleOption <i>other</i>)</li><li><div class="fn" /><b><a href="qstyleoption.html#init">init</a></b> (<i>self</i>, QWidget <i>w</i>)</li><li><div class="fn" /><b><a href="qstyleoption.html#initFrom">initFrom</a></b> (<i>self</i>, QWidget <i>w</i>)</li></ul><h3>Members</h3><ul><li><div class="fn" />Qt.LayoutDirection <b><a href="qstyleoption.html#direction-var">direction</a></b></li><li><div class="fn" />QFontMetrics <b><a href="qstyleoption.html#fontMetrics-var">fontMetrics</a></b></li><li><div class="fn" />QPalette <b><a href="qstyleoption.html#palette-var">palette</a></b></li><li><div class="fn" />QRect <b><a href="qstyleoption.html#rect-var">rect</a></b></li><li><div class="fn" />QStyle.State <b><a href="qstyleoption.html#state-var">state</a></b></li><li><div class="fn" />int <b><a href="qstyleoption.html#type-var">type</a></b></li><li><div class="fn" />int <b><a href="qstyleoption.html#version-var">version</a></b></li></ul><h3>Static Members</h3><ul><li><div class="fn" />int <b><a href="qstyleoption.html#Type-var">Type</a></b></li><li><div class="fn" />int <b><a href="qstyleoption.html#Version-var">Version</a></b></li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStyleOption class stores the parameters used by <a href="qstyle.html">QStyle</a> functions.</p>
<p>QStyleOption and its subclasses contain all the information that <a href="qstyle.html">QStyle</a> functions need to draw a graphical element.</p>
<p>For performance reasons, there are few member functions and the access to the member variables is direct (i.e., using the <tt>.</tt> or <tt>-></tt> operator). This low-level feel makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.</p>
<p>The caller of a <a href="qstyle.html">QStyle</a> function usually creates QStyleOption objects on the stack. This combined with Qt's extensive use of <a href="shclass.html#implicit-sharing">implicit sharing</a> for types such as <a href="qstring.html">QString</a>, <a href="qpalette.html">QPalette</a>, and <a href="qcolor.html">QColor</a> ensures that no memory allocation needlessly takes place.</p>
<p>The following code snippet shows how to use a specific QStyleOption subclass to paint a push button:</p>
<pre>
void MyPushButton.paintEvent(QPaintEvent *)
{
QStyleOptionButton option;
option.initFrom(this);
option.state = isDown() ? QStyle.State_Sunken : QStyle.State_Raised;
if (isDefault())
option.features |= QStyleOptionButton.DefaultButton;
option.text = text();
option.icon = icon();
QPainter painter(this);
style().drawControl(QStyle.CE_PushButton, &option, &painter, this);
}
</pre>
<p>In our example, the control is a <a href="qstyle.html#ControlElement-enum">QStyle.CE_PushButton</a>, and according to the <a href="qstyle.html#drawControl">QStyle.drawControl</a>() documentation the corresponding class is <a href="qstyleoptionbutton.html">QStyleOptionButton</a>.</p>
<p>When reimplementing <a href="qstyle.html">QStyle</a> functions that take a QStyleOption parameter, you often need to cast the QStyleOption to a subclass. For safety, you can use qstyleoption_cast<T>() to ensure that the pointer type is correct. For example:</p>
<pre>
void MyStyle.drawPrimitive(PrimitiveElement element,
const QStyleOption *option,
QPainter *painter,
const QWidget *widget)
{
if (element == PE_FocusRect) {
const QStyleOptionFocusRect *focusRectOption =
qstyleoption_cast<const QStyleOptionFocusRect *>(option);
if (focusRectOption) {
...
}
} else {
...
}
}
</pre>
<p>qstyleoption_cast<T>() will return 0 if the object to which <tt>option</tt> points isn't of the correct type.</p>
<p>See also <a href="qstyle.html">QStyle</a> and <a href="qstylepainter.html">QStylePainter</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="OptionType-enum" />QStyleOption.OptionType</h3><p>This enum is used internally by <a href="qstyleoption.html">QStyleOption</a>, its subclasses, and <a href="qstyleoption.html#qstyleoption_cast">qstyleoption_cast</a>() to determine the type of style option. In general you do not need to worry about this unless you want to create your own <a href="qstyleoption.html">QStyleOption</a> subclass and your own styles.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Default</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top"><a href="qstyleoption.html">QStyleOption</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_FocusRect</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top"><a href="qstyleoptionfocusrect.html">QStyleOptionFocusRect</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Button</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Tab</tt></td>
<td align="center" valign="top"><tt>3</tt></td>
<td valign="top"><a href="qstyleoptiontab.html">QStyleOptionTab</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_TabWidgetFrame</tt></td>
<td align="center" valign="top"><tt>13</tt></td>
<td valign="top"><a href="qstyleoptiontabwidgetframe.html">QStyleOptionTabWidgetFrame</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_TabBarBase</tt></td>
<td align="center" valign="top"><tt>14</tt></td>
<td valign="top"><a href="qstyleoptiontabbarbase.html">QStyleOptionTabBarBase</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_MenuItem</tt></td>
<td align="center" valign="top"><tt>4</tt></td>
<td valign="top"><a href="qstyleoptionmenuitem.html">QStyleOptionMenuItem</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Complex</tt></td>
<td align="center" valign="top"><tt>0xf0000</tt></td>
<td valign="top"><a href="qstyleoptioncomplex.html">QStyleOptionComplex</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Slider</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptionslider.html">QStyleOptionSlider</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Frame</tt></td>
<td align="center" valign="top"><tt>5</tt></td>
<td valign="top"><a href="qstyleoptionframe.html">QStyleOptionFrame</a> <a href="qstyleoptionframev2.html">QStyleOptionFrameV2</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_GroupBox</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptiongroupbox.html">QStyleOptionGroupBox</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ProgressBar</tt></td>
<td align="center" valign="top"><tt>6</tt></td>
<td valign="top"><a href="qstyleoptionprogressbar.html">QStyleOptionProgressBar</a> <a href="qstyleoptionprogressbarv2.html">QStyleOptionProgressBarV2</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Q3ListView</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptionq3listview.html">QStyleOptionQ3ListView</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Q3ListViewItem</tt></td>
<td align="center" valign="top"><tt>11</tt></td>
<td valign="top"><a href="qstyleoptionq3listviewitem.html">QStyleOptionQ3ListViewItem</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Header</tt></td>
<td align="center" valign="top"><tt>8</tt></td>
<td valign="top"><a href="qstyleoptionheader.html">QStyleOptionHeader</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_Q3DockWindow</tt></td>
<td align="center" valign="top"><tt>9</tt></td>
<td valign="top"><a href="qstyleoptionq3dockwindow.html">QStyleOptionQ3DockWindow</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_DockWidget</tt></td>
<td align="center" valign="top"><tt>10</tt></td>
<td valign="top"><a href="qstyleoptiondockwidget.html">QStyleOptionDockWidget</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_SpinBox</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptionspinbox.html">QStyleOptionSpinBox</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ToolButton</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptiontoolbutton.html">QStyleOptionToolButton</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ComboBox</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptioncombobox.html">QStyleOptionComboBox</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ToolBox</tt></td>
<td align="center" valign="top"><tt>7</tt></td>
<td valign="top"><a href="qstyleoptiontoolbox.html">QStyleOptionToolBox</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ToolBar</tt></td>
<td align="center" valign="top"><tt>16</tt></td>
<td valign="top"><a href="qstyleoptiontoolbar.html">QStyleOptionToolBar</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_RubberBand</tt></td>
<td align="center" valign="top"><tt>15</tt></td>
<td valign="top"><a href="qstyleoptionrubberband.html">QStyleOptionRubberBand</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_TitleBar</tt></td>
<td align="center" valign="top"> </td>
<td valign="top"><a href="qstyleoptiontitlebar.html">QStyleOptionTitleBar</a></td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ViewItem</tt></td>
<td align="center" valign="top"><tt>12</tt></td>
<td valign="top"><a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a> (used in Interviews)</td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_CustomBase</tt></td>
<td align="center" valign="top"><tt>0xf00</tt></td>
<td valign="top">Reserved for custom QStyleOptions; all custom controls values must be above this value</td>
</tr>
<tr>
<td valign="top"><tt>QStyleOption.SO_ComplexCustomBase</tt></td>
<td align="center" valign="top"><tt>0xf000000</tt></td>
<td valign="top">Reserved for custom QStyleOptions; all custom complex controls values must be above this value</td>
</tr>
</table>
<br />
<br />
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStyleOption" />QStyleOption.__init__ (<i>self</i>, int <i>version</i> = QStyleOption.Version, int <i>type</i> = QStyleOption.SO_Default)</h3><p>Constructs a <a href="qstyleoption.html">QStyleOption</a> with version <i>version</i> and type <i>type</i>.</p>
<p>The version has no special meaning for <a href="qstyleoption.html">QStyleOption</a>; it can be used by subclasses to distinguish between different version of the same option type.</p>
<p>The <a href="qstyleoption.html#state-var">state</a> member variable is initialized to <a href="qstyle.html#StateFlag-enum">QStyle.State_None</a>.</p>
<p>See also <a href="qstyleoption.html#version-varx">version</a> and <a href="qstyleoption.html#type-varx">type</a>.</p>
<h3 class="fn"><a name="QStyleOption-2" />QStyleOption.__init__ (<i>self</i>, <a href="qstyleoption.html">QStyleOption</a> <i>other</i>)</h3><p>Constructs a copy of <i>other</i>.</p>
<h3 class="fn"><a name="init" />QStyleOption.init (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><h3 class="fn"><a name="initFrom" />QStyleOption.initFrom (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>Initializes the <a href="qstyleoption.html#state-var">state</a>, <a href="qstyleoption.html#direction-var">direction</a>, <a href="qstyleoption.html#rect-var">rect</a>, <a href="qstyleoption.html#palette-var">palette</a>, and <a href="qstyleoption.html#fontMetrics-var">fontMetrics</a> member variables based on <i>widget</i>.</p>
<p>This function is provided only for convenience. You can also initialize the variables manually if you want.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qwidget.html#layoutDirection-prop">QWidget.layoutDirection</a>(), <a href="qwidget.html#rect-prop">QWidget.rect</a>(), <a href="qwidget.html#palette-prop">QWidget.palette</a>(), and <a href="qwidget.html#fontMetrics">QWidget.fontMetrics</a>().</p>
<hr /><h2>Member Documentation</h2><h3 class="fn"><a name="direction-var" /><a href="qt.html#LayoutDirection-enum">Qt.LayoutDirection</a> direction</h3><p>This variable holds the text layout direction that should be used when drawing text in the control.</p>
<h3 class="fn"><a name="fontMetrics-var" /><a href="qfontmetrics.html">QFontMetrics</a> fontMetrics</h3><p>This variable holds the font metrics that should be used when drawing text in the control.</p>
<h3 class="fn"><a name="palette-var" /><a href="qpalette.html">QPalette</a> palette</h3><p>This variable holds the palette that should be used when painting the control.</p>
<h3 class="fn"><a name="rect-var" /><a href="qrect.html">QRect</a> rect</h3><p>This variable holds the area that should be used for various calculations and painting.</p>
<p>This can have different meanings for different types of elements. For example, for <a href="qstyle.html#ControlElement-enum">QStyle.CE_PushButton</a> it would be the rectangle for the entire button, while for <a href="qstyle.html#ControlElement-enum">QStyle.CE_PushButtonLabel</a> it would be just the area for the push button label.</p>
<h3 class="fn"><a name="state-var" /><a href="qstyle-state.html">QStyle.State</a> state</h3><p>This variable holds the style flags that are used when drawing the control.</p>
<p>See also <a href="qstyle.html#drawPrimitive">QStyle.drawPrimitive</a>(), <a href="qstyle.html#drawControl">QStyle.drawControl</a>(), <a href="qstyle.html#drawComplexControl">QStyle.drawComplexControl</a>(), and <a href="qstyle.html#StateFlag-enum">QStyle.State</a>.</p>
<h3 class="fn"><a name="Type-var" />int Type</h3><p>This member should be treated as a constant.</p><p>Equals <a href="qstyleoption.html#OptionType-enum">SO_Default</a>.</p>
<h3 class="fn"><a name="type-var" />int type</h3><h3 class="fn"><a name="Version-var" />int Version</h3><p>This member should be treated as a constant.</p><p>Equals 1.</p>
<h3 class="fn"><a name="version-var" />int version</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt 4.0.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.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|