• PySide 模块
  • PySide.QtCore
  • 内容表

    上一话题

    QSocketNotifier

    下一话题

    QMimeData

    QSignalMapper

    概要

    函数

    信号

    详细描述

    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.

    class PySide.QtCore. QSignalMapper ( [ parent=None ] )
    参数: parent PySide.QtCore.QObject

    构造 PySide.QtCore.QSignalMapper 采用父级 parent .

    PySide.QtCore.QSignalMapper. map ( sender )
    参数: sender PySide.QtCore.QObject

    This slot emits signals based on the sender 对象。

    PySide.QtCore.QSignalMapper. map ( )

    This slot emits signals based on which object sends signals to it.

    PySide.QtCore.QSignalMapper. mapped ( arg__1 )
    参数: arg__1 PySide.QtCore.int
    PySide.QtCore.QSignalMapper. mapped ( arg__1 )
    参数: arg__1 – unicode
    PySide.QtCore.QSignalMapper. mapped ( arg__1 )
    参数: arg__1 PySide.QtGui.QWidget
    PySide.QtCore.QSignalMapper. mapped ( arg__1 )
    参数: arg__1 PySide.QtCore.QObject
    PySide.QtCore.QSignalMapper. 映射 ( id )
    参数: id PySide.QtCore.int
    返回类型: PySide.QtCore.QObject

    Returns the sender PySide.QtCore.QObject that is associated with the id .

    PySide.QtCore.QSignalMapper. 映射 ( text )
    参数: text – unicode
    返回类型: PySide.QtCore.QObject

    此函数重载 PySide.QtCore.QSignalMapper.mapping() .

    PySide.QtCore.QSignalMapper. 映射 ( widget )
    参数: widget PySide.QtGui.QWidget
    返回类型: PySide.QtCore.QObject

    此函数重载 PySide.QtCore.QSignalMapper.mapping() .

    Returns the sender PySide.QtCore.QObject that is associated with the widget .

    PySide.QtCore.QSignalMapper. 映射 ( object )
    参数: object PySide.QtCore.QObject
    返回类型: PySide.QtCore.QObject

    此函数重载 PySide.QtCore.QSignalMapper.mapping() .

    Returns the sender PySide.QtCore.QObject that is associated with the object .

    PySide.QtCore.QSignalMapper. removeMappings ( sender )
    参数: sender PySide.QtCore.QObject

    Removes all mappings for sender .

    This is done automatically when mapped objects are destroyed.

    PySide.QtCore.QSignalMapper. setMapping ( sender , text )
    参数:

    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.

    PySide.QtCore.QSignalMapper. setMapping ( sender , widget )
    参数:

    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.

    PySide.QtCore.QSignalMapper. setMapping ( sender , object )
    参数:

    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.

    PySide.QtCore.QSignalMapper. setMapping ( sender , id )
    参数:

    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.