PDA

View Full Version : Exclude items in QGraphicsItem::collidingItems



Affenbrotbaum
22nd January 2010, 04:38
Hello Community,

I have a grid set up in a QGraphicsView with some lines drawn. Now when I draw rectangles on it and I just want to check for collisions between the rectangles but QGraphicsItem::collidingItems, which I subclassed also returns the collisions between the Lines and the Rectangles. Is there any way around that?

Thanks
Alex

aamer4yu
22nd January 2010, 04:41
Didnt get what problem you have exactly.. can u explain the problem more ?

Affenbrotbaum
22nd January 2010, 05:38
Thanks for the swift reply.

I have a Scene where I added Lines and Rectangles. Now when I check a rectangle if it collides with another rectangle (I only want a true/false answer) then it also gives me back the number of collisions with the Lines. Is there a way to either exclude the lines from the collisions or to check specifically for collisions with rectangles?

Cheers
Alex

jano_alex_es
22nd January 2010, 07:57
You can cast all the items of the list.


if(static_cast<QGraphicsRectItem*>( myList.at(i)) != 0){//it's a rectangle}

agh, I've seen now you have subclassed them. So you can cast using qgraphicsitem_cast instead. But, at the beginning of each clas you'll need to add:


enum { Type = UserType + 1 }; //+1 because it's the first class, the next subclassed class will be +2 and so on

int type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}

Affenbrotbaum
22nd January 2010, 20:45
I added the enumeration and reimplemented the type() function, but when I cast it, it still returns a 0 pointer.
Is it maybe possible to draw the lines on one scene, and everything else on another scene and let the graphicsview show both?

Attached you'll find my src as a zip

Thanks
Alex