Results 1 to 2 of 2

Thread: Getting the bounding rectangle

  1. #1
    Join Date
    Apr 2008
    Thanked 1 Time in 1 Post
    Qt products
    Unix/X11 Windows

    Default Getting the bounding rectangle

    I have implemented the following code

    Qt Code:
    1. QRectF rect(0, 0, height(), Margin);
    2. painter->save();
    3. painter->translate(50,0);
    4. painter->rotate(90);
    5. painter->drawText(rect,Qt::AlignCenter | Qt::AlignTop,str);
    6. strBoundingRect = painter->boundingRect(rect,Qt::AlignCenter,str);
    7. painter->restore();
    To copy to clipboard, switch view to plain text mode 

    However, using the above code return in strBoundingRect the initial bounding rectangle of the QString str and not the one that corresponds to the rotated and translated painter.

    Can you give me an example on how can I obtain the bounding rectangle taking also into account both translation and rotation?

    Thanks in advance...
    Last edited by ioannis; 21st May 2009 at 15:49.

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Getting the bounding rectangle

    Rotate and translate the received bounding rect.

    Qt Code:
    1. QTransform t;
    2. t.rotate(...);
    3. t.translate(...);
    4. QRect transformed = t.mapRect(r);
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    ioannis (22nd May 2009)

Similar Threads

  1. Rotating a rectangle about its origin
    By babu198649 in forum Newbie
    Replies: 5
    Last Post: 25th October 2008, 13:24
  2. How to get a round rectangle (QRegion)
    By quzcFroal in forum Qt Programming
    Replies: 7
    Last Post: 2nd June 2008, 22:14
  3. Display rectangle on Image
    By parmar ranjit in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 14:09
  4. Draw a rectangle alternating two colors with qPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 00:12
  5. How to paint a selection rectangle on a pixmap?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2006, 20:52


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.