File: qsignalmapper.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 (89 lines) | stat: -rw-r--r-- 12,848 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
<?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>QSignalMapper 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">QSignalMapper Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QSignalMapper class bundles signals from identifiable senders. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsignalmapper.html#QSignalMapper">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qsignalmapper.html#map">map</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#map-2">map</a></b> (<i>self</i>, QObject&#160;<i>sender</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping">mapping</a></b> (<i>self</i>, int&#160;<i>id</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-2">mapping</a></b> (<i>self</i>, QString&#160;<i>text</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-3">mapping</a></b> (<i>self</i>, QWidget&#160;<i>widget</i>)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-4">mapping</a></b> (<i>self</i>, QObject&#160;<i>object</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#removeMappings">removeMappings</a></b> (<i>self</i>, QObject&#160;<i>sender</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping">setMapping</a></b> (<i>self</i>, QObject&#160;<i>sender</i>, int&#160;<i>id</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-2">setMapping</a></b> (<i>self</i>, QObject&#160;<i>sender</i>, QString&#160;<i>text</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-3">setMapping</a></b> (<i>self</i>, QObject&#160;<i>sender</i>, QWidget&#160;<i>widget</i>)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-4">setMapping</a></b> (<i>self</i>, QObject&#160;<i>sender</i>, QObject&#160;<i>object</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped">mapped</a></b> (int)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-2">mapped</a></b> (const QString&amp;)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-3">mapped</a></b> (QWidget *)</li><li><div class="fn" />void <b><a href="qsignalmapper.html#mapped-4">mapped</a></b> (QObject *)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSignalMapper class bundles signals from identifiable senders.</p>
<p>This class collects a set of parameterless signals, and re-emits them with integer, string or widget parameters corresponding to the object that sent the signal.</p>
<p>The class supports the mapping of particular strings or integers with particular objects using <a href="qsignalmapper.html#setMapping">setMapping</a>(). The objects' signals can then be connected to the <a href="qsignalmapper.html#map">map</a>() slot which will emit the <a href="qsignalmapper.html#mapped">mapped</a>() signal with the string or integer associated with the original signalling object. Mappings can be removed later using <a href="qsignalmapper.html#removeMappings">removeMappings</a>().</p>
<p>Example: Suppose we want to create a custom widget that contains a group of buttons (like a tool palette). One approach is to connect each button's <tt>clicked()</tt> signal to its own custom slot; but in this example we want to connect all the buttons to a single slot and parameterize the slot by the button that was clicked.</p>
<p>Here's the definition of a simple custom widget that has a single signal, <tt>clicked()</tt>, which is emitted with the text of the button that was clicked:</p>
<pre>
    class ButtonWidget : public QWidget
    {
        Q_OBJECT

    public:
        ButtonWidget(QStringList texts, QWidget *parent = 0);

    signals:
        void clicked(const QString &amp;text);

    private:
        QSignalMapper *signalMapper;
    };
</pre>
<p>The only function that we need to implement is the constructor:</p>
<pre>
    ButtonWidget.ButtonWidget(QStringList texts, QWidget *parent)
        : QWidget(parent)
    {
        signalMapper = new QSignalMapper(this);

        QGridLayout *gridLayout = new QGridLayout;
        for (int i = 0; i &lt; texts.size(); ++i) {
            QPushButton *button = new QPushButton(texts[i]);
            connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
            signalMapper-&gt;setMapping(button, texts[i]);
            gridLayout-&gt;addWidget(button, i / 3, i % 3);
        }

        connect(signalMapper, SIGNAL(mapped(const QString &amp;)),
                this, SIGNAL(clicked(const QString &amp;)));

        setLayout(gridLayout);
    }
</pre>
<p>A list of texts is passed to the constructor. A signal mapper is constructed and for each text in the list a <a href="qpushbutton.html">QPushButton</a> is created. We connect each button's <tt>clicked()</tt> signal to the signal mapper's <a href="qsignalmapper.html#map">map</a>() slot, and create a mapping in the signal mapper from each button to the button's text. Finally we connect the signal mapper's <a href="qsignalmapper.html#mapped">mapped</a>() signal to the custom widget's <tt>clicked()</tt> signal. When the user clicks a button, the custom widget will emit a single <tt>clicked()</tt> signal whose argument is the text of the button the user clicked.</p>
<p>See also <a href="qobject.html">QObject</a>, <a href="qbuttongroup.html">QButtonGroup</a>, and <a href="qactiongroup.html">QActionGroup</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSignalMapper" />QSignalMapper.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;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 <a href="qsignalmapper.html">QSignalMapper</a> with parent <i>parent</i>.</p>
<h3 class="fn"><a name="map" />QSignalMapper.map (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void map()</tt>.</p><p>This slot emits signals based on which object sends signals to it.</p>
<h3 class="fn"><a name="map-2" />QSignalMapper.map (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void map(QObject *)</tt>.</p><p>This is an overloaded member function, provided for convenience.</p>
<p>This slot emits signals based on the <i>sender</i> object.</p>
<h3 class="fn"><a name="mapping" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, int&#160;<i>id</i>)</h3><p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the given <i>id</i>.</p>
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapping-2" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>text</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<h3 class="fn"><a name="mapping-3" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, QWidget&#160;<i>widget</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the given <i>widget</i>.</p>
<h3 class="fn"><a name="mapping-4" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>object</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the given <i>object</i>.</p>
<h3 class="fn"><a name="removeMappings" />QSignalMapper.removeMappings (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>)</h3><p>Removes all mappings for <i>sender</i>.</p>
<p>This is done automatically when mapped objects are destroyed.</p>
<h3 class="fn"><a name="setMapping" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>, int&#160;<i>id</i>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the given <i>sender</i>, the signal mapped(<i>id</i>) is emitted.</p>
<p>There may be at most one integer ID for each sender.</p>
<p>See also <a href="qsignalmapper.html#mapping">mapping</a>().</p>
<h3 class="fn"><a name="setMapping-2" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>, <a href="qstring.html">QString</a>&#160;<i>text</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the given <i>sender</i>, the signal mapped(<i>text</i> ) is emitted.</p>
<p>There may be at most one text for each sender.</p>
<h3 class="fn"><a name="setMapping-3" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>, QWidget&#160;<i>widget</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the given <i>sender</i>, the signal mapped(<i>widget</i> ) is emitted.</p>
<p>There may be at most one widget for each sender.</p>
<h3 class="fn"><a name="setMapping-4" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>sender</i>, <a href="qobject.html">QObject</a>&#160;<i>object</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the given <i>sender</i>, the signal mapped(<i>object</i> ) is emitted.</p>
<p>There may be at most one object for each sender.</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="mapped" />void mapped (int)</h3><p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that has an integer mapping set. The object's mapped integer is passed in <i>i</i>.</p>
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-2" />void mapped (const QString&amp;)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that has a string mapping set. The object's mapped string is passed in <i>text</i>.</p>
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-3" />void mapped (QWidget *)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that has a widget mapping set. The object's mapped widget is passed in <i>widget</i>.</p>
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</a>().</p>
<h3 class="fn"><a name="mapped-4" />void mapped (QObject *)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>This signal is emitted when <a href="qsignalmapper.html#map">map</a>() is signalled from an object that has an object mapping set. The object provided by the map is passed in <i>object</i>.</p>
<p>See also <a href="qsignalmapper.html#setMapping">setMapping</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>