*** GMX Spamverdacht *** [PyQt] Robot example
lievbuts at vub.ac.be
Sun May 20 21:36:18 BST 2007
On Sunday 20 May 2007 19:05, Andreas Pakulat wrote:
> On 20.05.07 18:46:46, Lieven Buts wrote:
> > 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).
> IIRC you do it like this:
> in Python
OK, this works, both for QColor and QPixmap.
> > 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.
> instanceof can be used I guess, but I'd need more context to know for
> sure, i.e. in which class is this code?
There is a RobotPart base class, which is subclassed into RobotHead,
RobotTorso and RobotLimb. RobotPart implements a dragEnterEvent
method with a special case for RobotHead instances. I am now using
isinstance(self, RobotHead), following Paul's suggestion.
> > 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.
> No, QTimer should work in the main thread as well, at least if you
> started the QApplication via QApplication._exec()
Then I must be missing something. I think I have converted all the code from
the C++ files, but the animation does not start.
Current version at
More information about the PyQt