The PySide.QtCore.QSignalMapper class bundles signals from identifiable senders.
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.
The class supports the mapping of particular strings or integers with particular objects using PySide.QtCore.QSignalMapper.setMapping() . The objects’ signals can then be connected to the PySide.QtCore.QSignalMapper.map() slot which will emit the PySide.QtCore.QSignalMapper.mapped() signal with the string or integer associated with the original signalling object. Mappings can be removed later using PySide.QtCore.QSignalMapper.removeMappings() .
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 clicked() 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.
Here’s the definition of a simple custom widget that has a single signal, clicked() , which is emitted with the text of the button that was clicked:
class ButtonWidget(QWidget): def __init__(self, texts, parent=None): QWidget.__init__(self, parent) ...The only function that we need to implement is the constructor:
def __init__(self, texts, parent): QWidget.__init__(self, parent) self.signalMapper = QSignalMapper(self) layout = QGridLayout() for text, index in enumerate(texts): button = QPushButton(text) self.connect(SIGNAL("clicked()"), self.signalMapper, SLOT("map()")) self.signalMapper.setMapping(button, text) layout.addWidget(button, index / 3, index % 3) self.signalMapper.connect(SIGNAL("mapped(const QString &)"), self, SLOT("clicked(const QString &)")) self.setLayout(layout)A list of texts is passed to the constructor. A signal mapper is constructed and for each text in the list a PySide.QtGui.QPushButton is created. We connect each button’s clicked() signal to the signal mapper’s PySide.QtCore.QSignalMapper.map() slot, and create a mapping in the signal mapper from each button to the button’s text. Finally we connect the signal mapper’s PySide.QtCore.QSignalMapper.mapped() signal to the custom widget’s clicked() signal. When the user clicks a button, the custom widget will emit a single clicked() signal whose argument is the text of the button the user clicked.
Parameters: | parent – PySide.QtCore.QObject |
---|
Constructs a PySide.QtCore.QSignalMapper with parent parent .
Parameters: | sender – PySide.QtCore.QObject |
---|
This slot emits signals based on the sender object.
This slot emits signals based on which object sends signals to it.
Parameters: | arg__1 – PySide.QtCore.int |
---|
Parameters: | arg__1 – unicode |
---|
Parameters: | arg__1 – PySide.QtGui.QWidget |
---|
Parameters: | arg__1 – PySide.QtCore.QObject |
---|
Parameters: | id – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.QObject |
Returns the sender PySide.QtCore.QObject that is associated with the id .
Parameters: | text – unicode |
---|---|
Return type: | PySide.QtCore.QObject |
This function overloads PySide.QtCore.QSignalMapper.mapping() .
Parameters: | widget – PySide.QtGui.QWidget |
---|---|
Return type: | PySide.QtCore.QObject |
This function overloads PySide.QtCore.QSignalMapper.mapping() .
Returns the sender PySide.QtCore.QObject that is associated with the widget .
Parameters: | object – PySide.QtCore.QObject |
---|---|
Return type: | PySide.QtCore.QObject |
This function overloads PySide.QtCore.QSignalMapper.mapping() .
Returns the sender PySide.QtCore.QObject that is associated with the object .
Parameters: | sender – PySide.QtCore.QObject |
---|
Removes all mappings for sender .
This is done automatically when mapped objects are destroyed.
Parameters: |
|
---|
Adds a mapping so that when PySide.QtCore.QSignalMapper.map() is signalled from the sender , the signal mapped(text ) is emitted.
There may be at most one text for each sender.
Parameters: |
|
---|
Adds a mapping so that when PySide.QtCore.QSignalMapper.map() is signalled from the sender , the signal mapped(widget ) is emitted.
There may be at most one widget for each sender.
Parameters: |
|
---|
Adds a mapping so that when PySide.QtCore.QSignalMapper.map() is signalled from the sender , the signal mapped(object ) is emitted.
There may be at most one object for each sender.
Parameters: |
|
---|
Adds a mapping so that when PySide.QtCore.QSignalMapper.map() is signalled from the given sender , the signal mapped(id ) is emitted.
There may be at most one integer ID for each sender.