<?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">  </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">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 <i>parent</i> = 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)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping">mapping</a></b> (<i>self</i>, int)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-2">mapping</a></b> (<i>self</i>, QString)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-3">mapping</a></b> (<i>self</i>, QWidget)</li><li><div class="fn" />QObject <b><a href="qsignalmapper.html#mapping-4">mapping</a></b> (<i>self</i>, QObject)</li><li><div class="fn" /><b><a href="qsignalmapper.html#removeMappings">removeMappings</a></b> (<i>self</i>, QObject)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping">setMapping</a></b> (<i>self</i>, QObject, int)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-2">setMapping</a></b> (<i>self</i>, QObject, QString)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-3">setMapping</a></b> (<i>self</i>, QObject, QWidget)</li><li><div class="fn" /><b><a href="qsignalmapper.html#setMapping-4">setMapping</a></b> (<i>self</i>, QObject, QObject)</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&)</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 &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 < texts.size(); ++i) { QPushButton *button = new QPushButton(texts[i]); connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); signalMapper->setMapping(button, texts[i]); gridLayout->addWidget(button, i / 3, i % 3); } connect(signalMapper, SIGNAL(mapped(const QString &)), this, SIGNAL(clicked(const QString &))); 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> <i>parent</i> = 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> <a name="//apple_ref/cpp/instm/QSignalMapper/~QSignalMapper" /> <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>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void map(QObject *)</tt>.</p><p>This slot emits signals based on the <i>sender</i> object.</p> <a name="//apple_ref/cpp/instm/QSignalMapper/mapped" /> <h3 class="fn"><a name="mapping" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, int)</h3><p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the <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>, QString)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p> <h3 class="fn"><a name="mapping-3" /><a href="qobject.html">QObject</a> QSignalMapper.mapping (<i>self</i>, QWidget)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p> <p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the <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>)</h3><p>This function overloads <a href="qsignalmapper.html#mapping">mapping</a>().</p> <p>Returns the sender <a href="qobject.html">QObject</a> that is associated with the <i>object</i>.</p> <a name="//apple_ref/cpp/instm/QSignalMapper/removeMappings" /> <h3 class="fn"><a name="removeMappings" />QSignalMapper.removeMappings (<i>self</i>, <a href="qobject.html">QObject</a>)</h3><p>Removes all mappings for <i>sender</i>.</p> <p>This is done automatically when mapped objects are destroyed.</p> <a name="//apple_ref/cpp/instm/QSignalMapper/setMapping" /> <h3 class="fn"><a name="setMapping" />QSignalMapper.setMapping (<i>self</i>, <a href="qobject.html">QObject</a>, int)</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>, QString)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the <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>, QWidget)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the <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>, <a href="qobject.html">QObject</a>)</h3><p>Adds a mapping so that when <a href="qsignalmapper.html#map">map</a>() is signalled from the <i>sender</i>, the signal mapped(<i>object</i> ) is emitted.</p> <p>There may be at most one object for each sender.</p> <p /><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="mapped" />void mapped (int)</h3><p>This is the default overload of this signal.</p><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&)</h3><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 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 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> <a name="//apple_ref/cpp/instm/QSignalMapper/mapping" /> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.7.4 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> 2010</td><td align="right" width="25%">Qt 4.6.3</td></tr></table></div></address></body></html>