[PyQt] Syntax for connecting to QGraphicsScene.changed signal?

Phil Thompson phil at riverbankcomputing.com
Fri Oct 15 09:12:17 BST 2010


On Thu, 14 Oct 2010 15:37:02 -0700, TP <wingusr at gmail.com> wrote:
> QGraphicsScene's changed signal is documented as:
> 
>    void changed (const QList<QRectF>&)
> 
> The "Qt Utility classes and their Python equivalents" section of
> "Chapter 10 Qt Class Hierarchy" of GUI Programming with Python: QT
> Edition (from http://www.commandprompt.com/community/pyqt/x3738) says:
> "You can always use a Python list wherever a QList is needed".

That book si for PyQt3.

> But defining a signal as:
> 
>    sceneChanged = QtCore.pyqtSignal(list)
> 
> and then doing:
> 
>    self._scene.changed.connect(self.sceneChanged)
> 
> results in the following exception:
> 
>    "TypeError: connect() failed between changed(QList<QRectF>) and
> sceneChanged()"
> 
> As a workaround, I was able to do the following:
> 
>     @QtCore.pyqtSlot(list)
>     def changed (self, rects):
>         self.sceneChanged.emit(rects)
> 
> With the following connect() statement:
> 
>     self._scene.changed.connect(self.changed)
> 
> But how can I directly connect my signal to QGraphicScene's changed
> signal without going through an intermediate python method?

Use the C++ type as a string...

    sceneChanged = QtCore.pyqtSignal('QList<QRectF>')

Phil


More information about the PyQt mailing list