Results 1 to 6 of 6

Thread: Rotate Item qgraphicsscene

  1. #1
    Join Date
    May 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Question Rotate Item qgraphicsscene

    Hello

    I try to rotate a item, the item was added in a graphicsscene, add the image jpg before the circle, i add the circle with mousepresevent with parameters xmouse and ymouse.




    the promlem when i rotate the item (circle) the rotating point it uses is the point 0,0 of the image jpg, as it shows in the image.

    numbers in the image
    1.- Qgraphicsscene inside the Qgraphicsview
    2.- Image JPG
    3.-Item (circle) rotate fine
    4.-Item (circle) rotate wrong


    Qt Code:
    1. a = math.pi/45* value
    2. sina = math.sin(a)
    3. cosa = math.cos(a)
    4. translationTransform=QTransform(1, 0, 0, 1, 0, 0);
    5. rotationTransform=QTransform(cosa, sina, -sina, cosa, 0, 0);
    6. scalingTransform=QTransform(1., 0, 0, 1.0, 0, 0);
    7. transform = scalingTransform * rotationTransform * translationTransform;
    8. self.scene.selectedItems()[0].setTransform(transform)
    To copy to clipboard, switch view to plain text mode 

    How i can do to rotate the circle from the center of the circle.


    Sorry for my english.

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate Item qgraphicsscene

    Your approach of combining a translation and a rotation should work. But should your translation not be in item coordinates? Thus contain something like image.width()/2 ?

    And I don't think that you have to calculate the rotation matrix manually. Just use:

    Qt Code:
    1. QTransform q;
    2. q.translate(image.width()/2,image.height()/2);
    3. q.rotate(a);
    4. q.translate(-image.width()/2,-image.height()/2);
    To copy to clipboard, switch view to plain text mode 

    This is probably not exactly right. Just guessing. You may need to swap the translations..

    HIH

    Johannes

  3. #3
    Join Date
    May 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Rotate Item qgraphicsscene

    Thanks your answer that help me, my mistake was when aadding the item

    Qt Code:
    1. self.myObj = QGraphicsEllipseItem(QtCore.QRectF([B]xmouse, ymouse[/B], ancho, alto), parent = None, scene = self.scene)
    To copy to clipboard, switch view to plain text mode 

    Changing xmose and ymouse for the image zero point.

    And then the circle rotate perfect

    Qt Code:
    1. self.myObj = QGraphicsEllipseItem(QtCore.QRectF(0, 0, width-circle, high-circle), parent = None, scene = self.scene)Ç
    To copy to clipboard, switch view to plain text mode 

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Rotate Item qgraphicsscene


  5. The following user says thank you to Lykurg for this useful post:

    JohannesMunk (6th July 2010)

  6. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate Item qgraphicsscene

    That indeed, simplifies the matter :->

    Joh

  7. #6
    Join Date
    May 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Rotate Item qgraphicsscene

    i read documentation but i never had seen "setTransformOriginPoint" just i needed.
    thanks.

Similar Threads

  1. QGraphicsScene item positioning
    By been_1990 in forum Qt Programming
    Replies: 7
    Last Post: 28th July 2009, 12:11
  2. problem in positioning item in QGraphicsScene()
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 8th May 2009, 06:41
  3. Moving an item in QGraphicsScene
    By prosass in forum Newbie
    Replies: 4
    Last Post: 28th March 2007, 14:21
  4. Crazy over the QGraphicsScene/Item
    By Morea in forum Qt Programming
    Replies: 6
    Last Post: 20th November 2006, 09:18
  5. QWidget item in QGraphicsScene
    By IUnknown in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 00:05

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.