File: qicon.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (112 lines) | stat: -rw-r--r-- 17,629 bytes parent folder | download
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
<?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>QIcon 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">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QIcon Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QIcon class provides scalable icons in different modes and states. <a href="#details">More...</a></p>
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qicon.html#Mode-enum">Mode</a></b> { Normal, Disabled, Active }</li><li><div class="fn" />enum <b><a href="qicon.html#State-enum">State</a></b> { On, Off }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qicon.html#QIcon">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qicon.html#QIcon-2">__init__</a></b> (<i>self</i>, QPixmap&#160;<i>pixmap</i>)</li><li><div class="fn" /><b><a href="qicon.html#QIcon-3">__init__</a></b> (<i>self</i>, QVariant)</li><li><div class="fn" /><b><a href="qicon.html#QIcon-4">__init__</a></b> (<i>self</i>, QIcon&#160;<i>other</i>)</li><li><div class="fn" /><b><a href="qicon.html#QIcon-5">__init__</a></b> (<i>self</i>, QString&#160;<i>fileName</i>)</li><li><div class="fn" /><b><a href="qicon.html#QIcon-6">__init__</a></b> (<i>self</i>, QIconEngine&#160;<i>engine</i>)</li><li><div class="fn" />QSize <b><a href="qicon.html#actualSize">actualSize</a></b> (<i>self</i>, QSize&#160;<i>size</i>, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" /><b><a href="qicon.html#addFile">addFile</a></b> (<i>self</i>, QString&#160;<i>fileName</i>, QSize&#160;<i>size</i>&#160;=&#160;QSize(), Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" /><b><a href="qicon.html#addPixmap">addPixmap</a></b> (<i>self</i>, QPixmap&#160;<i>pixmap</i>, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" />bool <b><a href="qicon.html#isDetached">isDetached</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qicon.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qicon.html#paint">paint</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, QRect&#160;<i>rect</i>, Qt.Alignment&#160;<i>alignment</i>&#160;=&#160;Qt.AlignCenter, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" /><b><a href="qicon.html#paint-2">paint</a></b> (<i>self</i>, QPainter&#160;<i>painter</i>, int&#160;<i>x</i>, int&#160;<i>y</i>, int&#160;<i>w</i>, int&#160;<i>h</i>, Qt.Alignment&#160;<i>alignment</i>&#160;=&#160;Qt.AlignCenter, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" />QPixmap <b><a href="qicon.html#pixmap">pixmap</a></b> (<i>self</i>, QSize&#160;<i>size</i>, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" />QPixmap <b><a href="qicon.html#pixmap-2">pixmap</a></b> (<i>self</i>, int&#160;<i>w</i>, int&#160;<i>h</i>, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" />QPixmap <b><a href="qicon.html#pixmap-3">pixmap</a></b> (<i>self</i>, int&#160;<i>extent</i>, Mode&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, State&#160;<i>state</i>&#160;=&#160;QIcon.Off)</li><li><div class="fn" />int <b><a href="qicon.html#serialNumber">serialNumber</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QIcon class provides scalable icons in different modes and states.</p>
<p>A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.</p>
<p>The simplest use of QIcon is to create one from a <a href="qpixmap.html">QPixmap</a> file or resource, and then use it, allowing Qt to work out all the required icon styles and sizes. For example:</p>
<pre>
    QToolButton *button = new QToolButton;
    button-&gt;setIcon(QIcon("open.xpm"));
</pre>
<p>Use the <a href="qimagereader.html#supportedImageFormats">QImageReader.supportedImageFormats</a>() and <a href="qimagewriter.html#supportedImageFormats">QImageWriter.supportedImageFormats</a>() functions to retrieve a complete list of the supported file formats.</p>
<p>When you retrieve a pixmap using pixmap(<a href="qsize.html">QSize</a>, Mode, State), and no pixmap for this given size, mode and state has been added with <a href="qicon.html#addFile">addFile</a>() or <a href="qicon.html#addPixmap">addPixmap</a>(), then QIcon will generate one on the fly. This pixmap generation happens in a <a href="qiconengine.html">QIconEngine</a>. The default engine scales pixmaps down if required, but never up, and it uses the current style to calculate a disabled appearance. By using custom icon engines, you can customize every aspect of generated icons. With <a href="qiconengineplugin.html">QIconEnginePlugin</a> it is possible to register different icon engines for different file suffixes, so you could provide a SVG icon engine or any other scalable format.</p>
<a id="making-classes-that-use-qicon" name="making-classes-that-use-qicon" />
<h3>Making Classes that Use QIcon</h3>
<p>If you write your own widgets that have an option to set a small pixmap, consider allowing a QIcon to be set for that pixmap. The Qt class <a href="qtoolbutton.html">QToolButton</a> is an example of such a widget.</p>
<p>Provide a method to set a QIcon, and when you draw the icon, choose whichever pixmap is appropriate for the current state of your widget. For example:</p>
<pre>
    void MyWidget.drawIcon(QPainter *painter, QPoint pos)
    {
        QPixmap pixmap = icon.pixmap(QSize(22, 22),
                                       isEnabled() ? QIcon.Normal
                                                   : QIcon.Disabled,
                                       isOn() ? QIcon.On
                                              : QIcon.Off);
        painter-&gt;drawPixmap(pos, pixmap);
    }
</pre>
<p>You might also make use of the <tt>Active</tt> mode, perhaps making your widget <tt>Active</tt> when the mouse is over the widget (see <a href="qwidget.html#enterEvent">QWidget.enterEvent</a>()), while the mouse is pressed pending the release that will activate the function, or when it is the currently selected item. If the widget can be toggled, the "On" mode might be used to draw a different icon.</p>
<p align="center"><img alt="QIcon" src="images/icon.png" /></p>
<p>See also <a href="guibooks.html#fowler">GUI Design Handbook: Iconic Label</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="Mode-enum" />QIcon.Mode</h3><p>This enum type describes the mode for which a pixmap is intended to be used. The currently defined modes are:</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>QIcon.Normal</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">Display the pixmap when the user is not interacting with the icon, but the functionality represented by the icon is available.</td>
</tr>
<tr>
<td valign="top"><tt>QIcon.Disabled</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">Display the pixmap when the functionality represented by the icon is not available.</td>
</tr>
<tr>
<td valign="top"><tt>QIcon.Active</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">Display the pixmap when the functionality represented by the icon is available and the user is interacting with the icon, for example, moving the mouse over it or clicking it.</td>
</tr>
</table>
<br />
<br />
<h3 class="fn"><a name="State-enum" />QIcon.State</h3><p>This enum describes the state for which a pixmap is intended to be used. The <i>state</i> can be:</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>QIcon.Off</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">Display the pixmap when the widget is in an "off" state</td>
</tr>
<tr>
<td valign="top"><tt>QIcon.On</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">Display the pixmap when the widget is in an "on" state</td>
</tr>
</table>
<br />
<br />
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QIcon" />QIcon.__init__ (<i>self</i>)</h3><p>Constructs a null icon.</p>
<h3 class="fn"><a name="QIcon-2" />QIcon.__init__ (<i>self</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>pixmap</i>)</h3><p>Constructs an icon from a <i>pixmap</i>.</p>
<h3 class="fn"><a name="QIcon-3" />QIcon.__init__ (<i>self</i>, <a href="qvariant.html">QVariant</a>)</h3><p>Constructs a copy of <i>other</i>. This is very fast.</p>
<h3 class="fn"><a name="QIcon-4" />QIcon.__init__ (<i>self</i>, <a href="qicon.html">QIcon</a>&#160;<i>other</i>)</h3><p>Constructs an icon from the file with the given <i>fileName</i>. The file will be loaded on demand.</p>
<p>If <i>fileName</i> contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.</p>
<p>The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the <a href="resources.html">Resource System</a> overview for details on how to embed images and other resource files in the application's executable.</p>
<p>Use the <a href="qimagereader.html#supportedImageFormats">QImageReader.supportedImageFormats</a>() and <a href="qimagewriter.html#supportedImageFormats">QImageWriter.supportedImageFormats</a>() functions to retrieve a complete list of the supported file formats.</p>
<h3 class="fn"><a name="QIcon-5" />QIcon.__init__ (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>fileName</i>)</h3><p>Creates an icon with a specific icon <i>engine</i>. The icon takes ownership of the engine.</p>
<h3 class="fn"><a name="QIcon-6" />QIcon.__init__ (<i>self</i>, <a href="qiconengine.html">QIconEngine</a>&#160;<i>engine</i>)</h3><p>The <i>engine</i> argument has it's ownership transferred to Qt.</p><h3 class="fn"><a name="actualSize" /><a href="qsize.html">QSize</a> QIcon.actualSize (<i>self</i>, <a href="qsize.html">QSize</a>&#160;<i>size</i>, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>Returns the actual size of the icon for the requested <i>size</i>, <i>mode</i>, and <i>state</i>. The result might be smaller than requested, but never larger.</p>
<p>See also <a href="qicon.html#pixmap">pixmap</a>() and <a href="qicon.html#paint">paint</a>().</p>
<h3 class="fn"><a name="addFile" />QIcon.addFile (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>fileName</i>, <a href="qsize.html">QSize</a>&#160;<i>size</i>&#160;=&#160;QSize(), <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>Adds a pixmap from the file with the given <i>fileName</i> to the icon, as a specialization for <i>size</i>, <i>mode</i> and <i>state</i>. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.</p>
<p>If <i>fileName</i> contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.</p>
<p>The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the <a href="resources.html">Resource System</a> overview for details on how to embed images and other resource files in the application's executable.</p>
<p>Use the <a href="qimagereader.html#supportedImageFormats">QImageReader.supportedImageFormats</a>() and <a href="qimagewriter.html#supportedImageFormats">QImageWriter.supportedImageFormats</a>() functions to retrieve a complete list of the supported file formats.</p>
<p>See also <a href="qicon.html#addPixmap">addPixmap</a>().</p>
<h3 class="fn"><a name="addPixmap" />QIcon.addPixmap (<i>self</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>pixmap</i>, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>Adds <i>pixmap</i> to the icon, as a specialization for <i>mode</i> and <i>state</i>.</p>
<p>Custom icon engines are free to ignore additionally added pixmaps.</p>
<p>See also <a href="qicon.html#addFile">addFile</a>().</p>
<h3 class="fn"><a name="isDetached" />bool QIcon.isDetached (<i>self</i>)</h3><h3 class="fn"><a name="isNull" />bool QIcon.isNull (<i>self</i>)</h3><p>Returns true if the icon is empty; otherwise returns false.</p>
<p>An icon is empty if it has neither a pixmap nor a filename.</p>
<p>Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.</p>
<h3 class="fn"><a name="paint" />QIcon.paint (<i>self</i>, <a href="qpainter.html">QPainter</a>&#160;<i>painter</i>, <a href="qrect.html">QRect</a>&#160;<i>rect</i>, <a href="qt-alignment.html">Qt.Alignment</a>&#160;<i>alignment</i>&#160;=&#160;Qt.AlignCenter, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>Uses the <i>painter</i> to paint the icon with specified <i>alignment</i>, required <i>mode</i>, and <i>state</i> into the rectangle <i>rect</i>.</p>
<p>See also <a href="qicon.html#actualSize">actualSize</a>() and <a href="qicon.html#pixmap">pixmap</a>().</p>
<h3 class="fn"><a name="paint-2" />QIcon.paint (<i>self</i>, <a href="qpainter.html">QPainter</a>&#160;<i>painter</i>, int&#160;<i>x</i>, int&#160;<i>y</i>, int&#160;<i>w</i>, int&#160;<i>h</i>, <a href="qt-alignment.html">Qt.Alignment</a>&#160;<i>alignment</i>&#160;=&#160;Qt.AlignCenter, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Paints the icon into the rectangle <a href="qrect.html">QRect</a>(<i>x</i>, <i>y</i>, <i>w</i>, <i>h</i>).</p>
<h3 class="fn"><a name="pixmap" /><a href="qpixmap.html">QPixmap</a> QIcon.pixmap (<i>self</i>, <a href="qsize.html">QSize</a>&#160;<i>size</i>, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><p>Returns a pixmap with the requested <i>size</i>, <i>mode</i>, and <i>state</i>, generating one if necessary. The pixmap might be smaller than requested, but never larger.</p>
<p>See also <a href="qicon-qt3.html#setPixmap">setPixmap</a>(), <a href="qicon.html#actualSize">actualSize</a>(), and <a href="qicon.html#paint">paint</a>().</p>
<h3 class="fn"><a name="pixmap-2" /><a href="qpixmap.html">QPixmap</a> QIcon.pixmap (<i>self</i>, int&#160;<i>w</i>, int&#160;<i>h</i>, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><h3 class="fn"><a name="pixmap-3" /><a href="qpixmap.html">QPixmap</a> QIcon.pixmap (<i>self</i>, int&#160;<i>extent</i>, <a href="qicon.html#Mode-enum">Mode</a>&#160;<i>mode</i>&#160;=&#160;QIcon.Normal, <a href="qicon.html#State-enum">State</a>&#160;<i>state</i>&#160;=&#160;QIcon.Off)</h3><h3 class="fn"><a name="serialNumber" />int QIcon.serialNumber (<i>self</i>)</h3><p>Returns a number that uniquely identifies the contents of this <a href="qicon.html">QIcon</a> object. This means that multiple <a href="qicon.html">QIcon</a> objects can have the same serial number as long as they refer to the same contents.</p>
<p>A null icon always has a serial number of 0.</p>
<p>See also <a href="qpixmap.html#serialNumber">QPixmap.serialNumber</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>