[PyQt] Robot example

Paul Giannaros ceruleanblaze at gmail.com
Sun May 20 17:58:08 BST 2007


On Sunday 20 May 2007 17:46:46 Lieven Buts wrote:
> Greetings all,
>
> in order to learn about PyQt I have been trying to port
> the "drag-and-drop robot" example from the Qt 4.2 distribution
> to Python. My current version can be found at
> http://ultr23.vub.ac.be/~lieven/pyqt/dragdroprobot-1.py
> and
> http://ultr23.vub.ac.be/~lieven/pyqt/head.png
>
> There are a number of issues that I haven't solved yet, and
> they are marked in the comments in the code.
>
> The most important ones are:
>
> 1) The QVariant system to pass color and image objects
> through the drag-and-drop mechanism. I can convert a QColor
> or QImage object to a QVariant, but I don't see the way
> to do the opposite (NOTES 1 and 3).
>
> 2) The C++ code uses
> "if (... || (qgraphicsitem_cast<RobotHead *>(this)) && ..."
> to test if a RobotPart object is an instance of the RobotHead subclass
> or not. I have cobbled some Python together to do the same test
> based on the __class__ attribute (NOTE 5), but it's not very elegant.

Use `isinstance(myObject, RobotHead)` instead

>
> 3) The animation does not work, and when the program exits, it
> prints the message "QObject::startTimer: QTimer can only be used with
> threads started with QThread". I guess it is necessary to explicitly
> create a QThread in Python, but my attempts so far have not succeeded.
>

I get the same message some time. It's QCanvasView related. It may be a PyQt 
bug -- it hasn't caused any problems for me, though -- my animations tend to 
work. I'd be interested if anyone has a fix!

> I'll continue looking into all these issues, but any suggestions
> would be very welcome.
>
> Cheers,




More information about the PyQt mailing list