[PyQt] Robot example

Lieven Buts lievbuts at vub.ac.be
Sun May 20 17:46:46 BST 2007


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.

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'll continue looking into all these issues, but any suggestions
would be very welcome.

Cheers,

-- 
Lieven Buts


More information about the PyQt mailing list