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

TP wingusr at gmail.com
Fri Oct 15 11:13:03 BST 2010


On Fri, Oct 15, 2010 at 1:12 AM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> 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
>

Aha. Now that you mention it, the solution seems obvious.


More information about the PyQt mailing list