2010/8/14 Philippe Crave <[email protected]> > not sure, but maybe you should set this flag: ItemClipsToShape > > > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsitem.html#GraphicsItemFlag-enum > > > 2010/8/14 Konrad Koller <[email protected]> > > > > In many games collision detection is important. In my case the game's > stones are mostly convex polygons. > > Therefore their bounding rectangle is not adequate for collision > detection and therefore I create them > > in the constructor of the class Stone(QGraphicsItem) as QPainterPaths > like so: > > > > self.path=QPainterPath() > > self.path.addPolygon(polygon) > > self.path.closeSubpath() > > > > Then their shape is simple: > > > > def shape(self): return self.path > > > > Their boundingRect (used elsewhere) is: > > > > def boundingRect(self): return self.path.boundingRect() > > > > For collision detection with already placed stones I write: > > > > for item in self.collidingItems(Qt.IntersectsItemShape): > > if isinstance(item,Stone): print "Collision!" > > > > To my surprise the detection does not recognize the shape but obviously > the boundingRect. > > For example: > > _________ > > |______ | > > ___ | |___ > > | | |_____| > > | | > > | |_ > > |____| > > > > This reports a "collision". Why? > > > > Thanks for any hint. Konrad > > Philippe Crave proposed the flag ItemClipsToShape, but this does not help. I suppose a fundamental error in the shape collision detection of Qt4/PyQt4. My experience is, that for the same QGraphicsItem the detection of a collision with a point (QGraphicsItem.contains(point)) works correctly even when the shape is of importance, but fails for the colliding detection with QGraphicsItems when the shape of the colliding item has to be recognized.
I think the experts of Qt4/PyQt4 should check this behavior and eventually try to correct it, otherwise in such cases the GUI would not be usable. Any further hint is welcome. Konrad
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
