Results 1 to 4 of 4

Thread: help scene()->collidingItems

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default help scene()->collidingItems

    Hi all,
    I have a problem of this kind, the management of collisions. To check if I have collision I use:
    Qt Code:
    1. if(scene()->collidingItems(this).isEmpty())
    To copy to clipboard, switch view to plain text mode 
    (this condition is carried out inside my robot item)
    when the condition is true, I would like to know against which item I had a collision with my item robot ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: help scene()->collidingItems

    collidingItems() returns a list of items the given item collides with.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help scene()->collidingItems

    Yes wysota, but given that I would get the name of the item (item robot collides with item obstacle), how do I?
    The problem could be solved using:
    Qt Code:
    1. if(collidesWithItem(ostacolo)) ...
    To copy to clipboard, switch view to plain text mode 
    having created a class Robot, derived from QGraphicsSvgItem, to see the class Obstacle (also derived from QGraphicsSvgItem) from that class I have to pass the reference to the instance Robot Obstacle, which I would rather avoid doing. So here is the need to extract the data from the list Obstacle collision. How to do this ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: help scene()->collidingItems

    Quote Originally Posted by giorgik View Post
    Yes wysota, but given that I would get the name of the item (item robot collides with item obstacle), how do I?
    Use regular C++ means to identify the item (e.g. comparing it against a stored pointer) or use rtti offered by QGraphicsItem (i.e. QGraphicsItem::type()). If you just need to know if an item collides with a particular single item then ask the framework about the collision directly (using collidesWithItem()).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. 3D scene into QML
    By Daxos in forum Qt Quick
    Replies: 0
    Last Post: 20th January 2012, 11:37
  2. Help with scene
    By justin123 in forum Newbie
    Replies: 1
    Last Post: 2nd July 2010, 04:43
  3. Exclude items in QGraphicsItem::collidingItems
    By Affenbrotbaum in forum Newbie
    Replies: 4
    Last Post: 22nd January 2010, 20:45
  4. graphics scene
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 08:55
  5. Creating a scene from piece of another scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 17:51

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.