1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/styles/qstyleoption.cpp -->
7
<title>Qt 4.0: QStyleOption Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<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="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="annotated.html"><font color="#004faf">Annotated</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QStyleOption Class Reference</h1>
21
<p>The QStyleOption class stores the parameters used by <a href="qstyle.html">QStyle</a> functions. <a href="#details">More...</a></p>
22
<pre>#include <QStyleOption></pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
23
<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="qstyleoptionq3dockwindow.html">QStyleOptionQ3DockWindow</a>, <a href="qstyleoptionq3listviewitem.html">QStyleOptionQ3ListViewItem</a>, <a href="qstyleoptionrubberband.html">QStyleOptionRubberBand</a>, <a href="qstyleoptiontab.html">QStyleOptionTab</a>, <a href="qstyleoptiontabwidgetframe.html">QStyleOptionTabWidgetFrame</a>, <a href="qstyleoptiontoolbox.html">QStyleOptionToolBox</a>, and <a href="qstyleoptionviewitem.html">QStyleOptionViewItem</a>.</p>
25
<li><a href="qstyleoption-members.html">List of all members, including inherited members</a></li>
27
<a name="public-types"></a>
30
<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>
32
<a name="public-functions"></a>
33
<h3>Public Functions</h3>
35
<li><div class="fn"/><b><a href="qstyleoption.html#QStyleOption">QStyleOption</a></b> ( int <i>version</i> = QStyleOption::Version, int <i>type</i> = SO_Default )</li>
36
<li><div class="fn"/><b><a href="qstyleoption.html#QStyleOption-2">QStyleOption</a></b> ( const QStyleOption & <i>other</i> )</li>
37
<li><div class="fn"/><b><a href="qstyleoption.html#dtor.QStyleOption">~QStyleOption</a></b> ()</li>
38
<li><div class="fn"/>void <b><a href="qstyleoption.html#init">init</a></b> ( const QWidget * <i>widget</i> )</li>
39
<li><div class="fn"/>QStyleOption & <b><a href="qstyleoption.html#operator-eq">operator=</a></b> ( const QStyleOption & <i>other</i> )</li>
41
<a name="public-variables"></a>
42
<h3>Public Variables</h3>
44
<li><div class="fn"/>Qt::LayoutDirection <b><a href="qstyleoption.html#direction-var">direction</a></b></li>
45
<li><div class="fn"/>QFontMetrics <b><a href="qstyleoption.html#fontMetrics-var">fontMetrics</a></b></li>
46
<li><div class="fn"/>QPalette <b><a href="qstyleoption.html#palette-var">palette</a></b></li>
47
<li><div class="fn"/>QRect <b><a href="qstyleoption.html#rect-var">rect</a></b></li>
48
<li><div class="fn"/>QStyle::State <b><a href="qstyleoption.html#state-var">state</a></b></li>
49
<li><div class="fn"/>int <b><a href="qstyleoption.html#type-varx">type</a></b></li>
50
<li><div class="fn"/>int <b><a href="qstyleoption.html#version-varx">version</a></b></li>
52
<a name="static-public-members"></a>
53
<h3>Static Public Members</h3>
55
<li><div class="fn"/>const int <b><a href="qstyleoption.html#Type-var">Type</a></b></li>
56
<li><div class="fn"/>const int <b><a href="qstyleoption.html#Version-var">Version</a></b></li>
58
<a name="related-non-members"></a>
59
<h3>Related Non-Members</h3>
61
<li><div class="fn"/>T <b><a href="qstyleoption.html#qstyleoption_cast">qstyleoption_cast</a></b> ( const QStyleOption * <i>option</i> )</li>
62
<li><div class="fn"/>T <b><a href="qstyleoption.html#qstyleoption_cast-3">qstyleoption_cast</a></b> ( QStyleOption * <i>option</i> )</li>
64
<a name="details"></a>
66
<h2>Detailed Description</h2>
67
<p>The QStyleOption class stores the parameters used by <a href="qstyle.html">QStyle</a> functions.</p>
68
<p>QStyleOption and its subclasses contain all the information that <a href="qstyle.html">QStyle</a> functions need to draw a graphical element.</p>
69
<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>
70
<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>
71
<p>The following code snippet shows how to use a specific QStyleOption subclass to paint a push button:</p>
72
<pre> void MyPushButton::paintEvent()
74
QStyleOptionButton option;
76
option.state = isDown() ? QStyle::State_Sunken : QStyle::State_Raised;
78
option.features |= QStyleOptionButton::DefaultButton;
82
QPainter painter(this);
83
style().drawControl(QStyle::CE_PushButton, &option, &painter, this);
85
<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>
86
<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>
87
<pre> void MyStyle::drawPrimitive(PrimitiveElement element,
88
const QStyleOption *option,
90
const QWidget *widget)
92
if (element == PE_FocusRect) {
93
const QStyleOptionFocusRect *focusRectOption =
94
qstyleoption_cast<const QStyleOptionFocusRect *>(option);
95
if (focusRectOption) {
102
<p>qstyleoption_cast<T>() will return 0 if the object to which <tt>option</tt> points isn't of the correct type.</p>
103
<p>See also <a href="qstyle.html">QStyle</a> and <a href="qstylepainter.html">QStylePainter</a>.</p>
105
<h2>Member Type Documentation</h2>
106
<h3 class="fn"><a name="OptionType-enum"></a>enum QStyleOption::OptionType</h3>
107
<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>
108
<table border="1" cellpadding="2" cellspacing="1" width="100%">
109
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
110
<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>
111
<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>
112
<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>
113
<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>
114
<tr><td valign="top"><tt>QStyleOption::SO_TabWidgetFrame</tt></td><td align="center" valign="top"><tt>13</tt></td><td valign="top"><a href="qstyleoptiontabbarbase.html">QStyleOptionTabBarBase</a></td></tr>
115
<tr><td valign="top"><tt>QStyleOption::SO_TabBarBase</tt></td><td align="center" valign="top"><tt>14</tt></td><td valign="top"><a href="qstyleoptiontabwidgetframe.html">QStyleOptionTabWidgetFrame</a></td></tr>
116
<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>
117
<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>
118
<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>
119
<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></td></tr>
120
<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></td></tr>
121
<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>
122
<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>
123
<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>
124
<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>
125
<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>
126
<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>
127
<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>
128
<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>
129
<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>
130
<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>
131
<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>
132
<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>
133
<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>
134
<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>
137
<h2>Member Function Documentation</h2>
138
<h3 class="fn"><a name="QStyleOption"></a>QStyleOption::QStyleOption ( int <i>version</i> = QStyleOption::Version, int <i>type</i> = SO_Default )</h3>
139
<p>Constructs a <a href="qstyleoption.html">QStyleOption</a> with version <i>version</i> and type <i>type</i>.</p>
140
<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>
141
<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>
142
<p>See also <a href="qstyleoption.html#version-varx">version</a> and <a href="qstyleoption.html#type-varx">type</a>.</p>
143
<h3 class="fn"><a name="QStyleOption-2"></a>QStyleOption::QStyleOption ( const QStyleOption & <i>other</i> )</h3>
144
<p>Constructs a copy of <i>other</i>.</p>
145
<h3 class="fn"><a name="dtor.QStyleOption"></a>QStyleOption::~QStyleOption ()</h3>
146
<p>Destroys the style option object.</p>
147
<h3 class="fn"><a name="init"></a>void QStyleOption::init ( const <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
148
<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>
149
<p>This function is provided only for convenience. You can also initialize the variables manually if you want.</p>
150
<h3 class="fn"><a name="operator-eq"></a>QStyleOption & QStyleOption::operator= ( const QStyleOption & <i>other</i> )</h3>
151
<p>Assign <i>other</i> to this <a href="qstyleoption.html">QStyleOption</a>.</p>
153
<h2>Member Variable Documentation</h2>
154
<h3 class="fn"><a name="Type-var"></a>const int QStyleOption::Type</h3>
155
<p>Equals <a href="qstyleoption.html#OptionType-enum">SO_Default</a>.</p>
156
<h3 class="fn"><a name="Version-var"></a>const int QStyleOption::Version</h3>
158
<h3 class="fn"><a name="direction-var"></a><a href="qt.html#LayoutDirection-enum">Qt::LayoutDirection</a> QStyleOption::direction</h3>
159
<p>This variable holds the text layout direction that should be used when drawing text in the control.</p>
160
<h3 class="fn"><a name="fontMetrics-var"></a><a href="qfontmetrics.html">QFontMetrics</a> QStyleOption::fontMetrics</h3>
161
<p>This variable holds the font metrics that should be used when drawing text in the control.</p>
162
<h3 class="fn"><a name="palette-var"></a><a href="qpalette.html">QPalette</a> QStyleOption::palette</h3>
163
<p>This variable holds the palette that should be used when painting the control.</p>
164
<h3 class="fn"><a name="rect-var"></a><a href="qrect.html">QRect</a> QStyleOption::rect</h3>
165
<p>This variable holds the area that should be used for various calculations and painting.</p>
166
<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>
167
<h3 class="fn"><a name="state-var"></a><a href="qstyle.html#StateFlag-enum">QStyle::State</a> QStyleOption::state</h3>
168
<p>This variable holds the style flags that are used when drawing the control.</p>
169
<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>
170
<h3 class="fn"><a name="type-varx"></a>int QStyleOption::type</h3>
171
<p>This variable holds the option type of the style option.</p>
172
<p>See also <a href="qstyleoption.html#OptionType-enum">OptionType</a>.</p>
173
<h3 class="fn"><a name="version-varx"></a>int QStyleOption::version</h3>
174
<p>This variable holds the version of the style option.</p>
175
<p>This value can be used by subclasses to implement extensions without breaking compatibility. If you use qstyleoption_cast<T>(), you normally don't need to check it.</p>
177
<h2>Related Non-Members</h2>
178
<h3 class="fn"><a name="qstyleoption_cast"></a>T qstyleoption_cast ( const QStyleOption * <i>option</i> )</h3>
179
<p>Returns a T or 0 depending on the <a href="qstyleoption.html#type-varx">type</a> and <a href="qstyleoption.html#version-varx">version</a> of <i>option</i>.</p>
181
<pre> void MyStyle::drawPrimitive(PrimitiveElement element,
182
const QStyleOption *option,
184
const QWidget *widget)
186
if (element == PE_FocusRect) {
187
const QStyleOptionFocusRect *focusRectOption =
188
qstyleoption_cast<const QStyleOptionFocusRect *>(option);
189
if (focusRectOption) {
195
<p>See also <a href="qstyleoption.html#type-varx">QStyleOption::type</a> and <a href="qstyleoption.html#version-varx">QStyleOption::version</a>.</p>
196
<h3 class="fn"><a name="qstyleoption_cast-3"></a>T qstyleoption_cast ( QStyleOption * <i>option</i> )</h3>
197
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
198
<p>Returns a T or 0 depending on the type of <i>option</i>.</p>
199
<p /><address><hr /><div align="center">
200
<table width="100%" cellspacing="0" border="0"><tr class="address">
201
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
202
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
203
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
204
</tr></table></div></address></body>