Results 1 to 6 of 6

Thread: Rotate a QRectF

  1. #1
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Rotate a QRectF

    Hi,

    i try to rotate a QRectF like this:
    Qt Code:
    1. QPainter painter(this);
    2. painter.rotate(270);
    3. QTextOption textOption(Qt::AlignCenter);
    4. painter.drawText( QRectF(50,50,100,20);, "Hello World", textOption );
    To copy to clipboard, switch view to plain text mode 

    but that code don't working. I would be rotate the QRectF at the QRectF center. How can i do that?

  2. #2
    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 a QRectF

    have a look at QMatrix and QTransform. (->translate)

  3. #3
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Rotate a QRectF

    Now i have try to rotate the QRectF like this:
    Qt Code:
    1. QRectF rect(50,50,100,20);
    2. QTransform transform;
    3. transform.rotate(270,Qt::XAxis);
    4. transform.translate(rect.width(), rect.height());
    5. QRectF transformed = transform.mapRect(rect);
    6.  
    7. QTextOption textOption(Qt::AlignCenter);
    8. painter.drawText( transformed, "Hello World", textOption );
    To copy to clipboard, switch view to plain text mode 

    but rotating with QTransform don't working too. What am i doing wrong?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Rotate a QRectF

    you need to use translate() to put the rotation center inside your rect's center and then use QRect(-50,-10,100,20)

  5. #5
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Rotate a QRectF

    QRectF(-50,-10,100,20) center the rect and QTransform::translate ( qreal dx, qreal dy ) is the x and y axis to paint the rect? My rec is not rotated and paint on the given x-coordinate and y-coordinate. What am I doing wrong again?

  6. #6
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Rotate a QRectF

    It's not necessary to use QMatrix and QTransform to rotate a QRectF. Important is to translate the painter before rotate and center the rect like the following example:

    Qt Code:
    1. QPainter painter(this);
    2. painter.translate(50, 50);
    3. painter.rotate(270);
    4.  
    5. QRectF rect(-50,-10,100,20);
    6. QTextOption textOption(Qt::AlignCenter);
    7. painter.drawText( rect, "Hello World", textOption );
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help!

Similar Threads

  1. resize and rotate handle
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 22nd February 2009, 14:03
  2. rotate operation and cpu usage
    By ersin.ozkan in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2008, 06:42
  3. how to rotate a rectangular region of awidget
    By babu198649 in forum Newbie
    Replies: 2
    Last Post: 17th March 2008, 13:39
  4. QMatrix rotate on QGraphicsTextItem speed on render..
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 22nd December 2007, 19:46
  5. To rotate widget
    By ajit in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2007, 10:03

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.