Results 1 to 2 of 2

Thread: translate and qgraphicsitem

  1. #1
    Join Date
    Jun 2009
    Location
    Seattle, WA
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default translate and qgraphicsitem

    Hello -
    I am writing a simple asteroids game and have a question about qgraphicsitems and the translate function. The app uses QGraphicsItems and QGraphicsScene and a timer that calls advance several times a second.

    I'd like the asteroid to have it's 0,0 coordinate in the center of the asteroid. I'm using QGraphicsRectItem to create a square asteroid and calling the constructor with setRect (-40, -40, 80, 80). This works and I get what I want.

    However, I should be able to create a rect with setRect (0,0,80,80) and then call QGraphicsItem::translate(-40, -40) to achieve the same thing. And no matter what I do, I can't get anything right. I've tried 40, 40 and -40, -40 and other combinations. I can't seem to find out what it's doing. Is the center being put in terms of scene coordinates? I'm wondering if I should be playing with mapfromscene or something like that.

    Thanks,
    Pat

  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: translate and qgraphicsitem

    I'd like the asteroid to have it's 0,0 coordinate in the center of the asteroid. I'm using QGraphicsRectItem to create a square asteroid and calling the constructor with setRect (-40, -40, 80, 80). This works and I get what I want.
    And thats how it works I guess... read more about the cordinate system in Qt Assistant.
    If you want to provide (0,0,80,80) and be able to translate (-40,-40), you will need to provide your own methods I guess.

Similar Threads

  1. transform() vs pos() for QGraphicsItem
    By aalexei in forum Qt Programming
    Replies: 9
    Last Post: 13th November 2012, 23:34
  2. QGraphicsItem meaning of pos(), scenePos()
    By nicolas1 in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2008, 08:59
  3. How to reflect QGraphicsItem?
    By Radagast in forum Qt Programming
    Replies: 15
    Last Post: 26th June 2008, 22:52
  4. mirror for QGraphicsItem
    By jobrandt in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2007, 09:09

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.