Results 1 to 2 of 2

Thread: How to rotate an object by its center?

  1. #1
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to rotate an object by its center?

    How to rotate(such as rectangle) an object by its center? I find the QPainter::rotate function is rotating an object by the point(0,0), not its center. So who can tell me how to do it? I use the QPainter::translate function before using the QPainter::rotate function,find it also work incorrect. Can you give me a simple sample to do it? thanks.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to rotate an object by its center?

    Quote Originally Posted by tszzp View Post
    How to rotate(such as rectangle) an object by its center? I find the QPainter::rotate function is rotating an object by the point(0,0), not its center. So who can tell me how to do it? I use the QPainter::translate function before using the QPainter::rotate function,find it also work incorrect. Can you give me a simple sample to do it? thanks.
    You need to translate your object's center to origin(the point of rotation), then rotate it and then re-translate it to its original position to get rotation from center.
    You can use QTransform for this.
    Click here for more info.
    Last edited by yogeshgokul; 10th November 2009 at 04:31.

Similar Threads

  1. Getting std::string object from QString object ( qt3)
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 28th March 2013, 20:09
  2. QList & QPointer to store object list
    By maddog_fr in forum Qt Programming
    Replies: 12
    Last Post: 8th August 2009, 20:39
  3. Replies: 4
    Last Post: 19th February 2009, 11:10
  4. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 17:31
  5. A form returning an object.
    By cbarmpar in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 05:21

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.