<br><br><div class="gmail_quote">2010/8/14 Philippe Crave <span dir="ltr"><<a href="mailto:philippe.crave@gmail.com">philippe.crave@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
not sure, but maybe you should set this flag: ItemClipsToShape<br>
<br>
<a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsitem.html#GraphicsItemFlag-enum" target="_blank">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsitem.html#GraphicsItemFlag-enum</a><br>

<br>
<br>
2010/8/14 Konrad Koller <<a href="mailto:koko9991@googlemail.com">koko9991@googlemail.com</a>><br>
<div><div></div><div class="h5">><br>
> In many games collision detection is important. In my case the game's stones are mostly convex polygons.<br>
> Therefore their bounding rectangle is not adequate for collision detection and therefore I create them<br>
> in the constructor of the class Stone(QGraphicsItem) as QPainterPaths like so:<br>
><br>
> self.path=QPainterPath()<br>
> self.path.addPolygon(polygon)<br>
> self.path.closeSubpath()<br>
><br>
> Then their shape is simple:<br>
><br>
> def shape(self): return self.path<br>
><br>
> Their boundingRect (used elsewhere) is:<br>
><br>
> def boundingRect(self): return self.path.boundingRect()<br>
><br>
> For collision detection with already placed stones I write:<br>
><br>
> for item in self.collidingItems(Qt.IntersectsItemShape):<br>
>     if isinstance(item,Stone): print "Collision!"<br>
><br>
> To my surprise the detection does not recognize the shape but obviously the boundingRect.<br>
> For example:<br>
> _________<br>
> |______    |<br>
>   ___    |   |___<br>
>  |     |    |_____|<br>
>  |     |<br>
>  |     |_<br>
>  |____|<br>
><br>
> This reports a "collision". Why?<br>
><br>
>  Thanks for any hint. Konrad<br><br></div></div></blockquote><div>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.<br>
<br>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.<br><br>Konrad<br></div></div><br>