Results 1 to 5 of 5

Thread: Exclude items in QGraphicsItem::collidingItems

  1. #1
    Join Date
    Jan 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Exclude items in QGraphicsItem::collidingItems

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exclude items in QGraphicsItem::collidingItems

    Didnt get what problem you have exactly.. can u explain the problem more ?

  3. #3
    Join Date
    Jan 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exclude items in QGraphicsItem::collidingItems

    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

  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Exclude items in QGraphicsItem::collidingItems

    You can cast all the items of the list.

    Qt Code:
    1. if(static_cast<QGraphicsRectItem*>( myList.at(i)) != 0){//it's a rectangle}
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. enum { Type = UserType + 1 }; //+1 because it's the first class, the next subclassed class will be +2 and so on
    2.  
    3. int type() const
    4. {
    5. // Enable the use of qgraphicsitem_cast with this item.
    6. return Type;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jano_alex_es; 22nd January 2010 at 08:01.

  5. #5
    Join Date
    Jan 2010
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exclude items in QGraphicsItem::collidingItems

    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
    Attached Files Attached Files

Similar Threads

  1. Replies: 7
    Last Post: 21st March 2010, 03:11
  2. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  3. Replies: 2
    Last Post: 28th June 2008, 16:31
  4. timerEvent for each QGraphicsItem
    By tts80 in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 09:33
  5. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 12:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.