[PyQt] Using new-style connections with QSignalMapper

Mark Visser markv at lumierevfx.com
Mon Mar 8 22:29:48 GMT 2010


Is there some reason new-style connection from any signal to 
QSignalMapper.map do not appear to work?

Using old-style self.connect works, i.e.:
|
        #self.connect(self.b1, SIGNAL("clicked()"),
        #             self.mapper, SLOT("map()"))
        #self.connect(self.b2, SIGNAL("clicked()"),
        #             self.mapper, SLOT("map()"))
|
But using new-style self.<signal>.connect does not:

|||        self.b1.clicked.connect(self.mapper.map)
        self.b2.clicked.connect(self.mapper.map)
|
Here's a complete example:|
=========================================
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication([])

class Test(QWidget):
    def __init__(self, parent=None):
        super(Test, self).__init__(parent)
        layout = QVBoxLayout()
       
        self.b1 = QPushButton("B1")
        self.b2 = QPushButton("B2")

        layout.addWidget(self.b1)
        layout.addWidget(self.b2)

        self.setLayout(layout)

        self.mapper = QSignalMapper(self)

        self.mapper.setMapping(self.b1, "B1")
        self.mapper.setMapping(self.b2, "B2")

        self.b1.clicked.connect(self.mapper.map)
        self.b2.clicked.connect(self.mapper.map)

        #self.connect(self.b1, SIGNAL("clicked()"),
        #             self.mapper, SLOT("map()"))
        #self.connect(self.b2, SIGNAL("clicked()"),
        #             self.mapper, SLOT("map()"))

        self.mapper.mapped[QString].connect(self.sayIt)

    @pyqtSlot(QString)
    def sayIt(self, name):
        print name
       

t = Test()

t.show()

app.exec_()
||=========================================|

cheers,
-Mark

-- 
Mark Visser, Software Director
Lumière VFX
Email: markv at lumierevfx.com
Phone: +1-514-316-1080 x3030

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100308/de857a52/attachment-0001.html>


More information about the PyQt mailing list