Results 1 to 2 of 2

Thread: QPainter.drawText and margin/padding

  1. #1
    Join Date
    Feb 2007
    Posts
    61
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPainter.drawText and margin/padding

    Hi

    I have a QRectF defined for drawing a rect and draw text inside of this visible rect.

    Qt Code:
    1. painter.fillRect(rect, bgColor);
    2. painter.drawText(rect, Qt::AlignRight, QString("A string"));
    To copy to clipboard, switch view to plain text mode 

    So instead of manually position the text I just reuse the same QRectF as for filling the Rect and align using the Qt::AlignRight. However, I would like to make a small padding (1-2 pixels) from the right-aligned text and the edge of the visible rect.

    Obviously I can do this by manually making the rect for drawText a couple of pixels shorter than the fillRect rect. However, before doing this I just want to make sure there aren't any cleaner way of defining padding when using drawText?

    Any ideas? Appreciate any answer, even it its just to confirm that I have to do this manually.

  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: QPainter.drawText and margin/padding

    Quote Originally Posted by invictus View Post
    Obviously I can do this by manually making the rect for drawText a couple of pixels shorter than the fillRect rect. However, before doing this I just want to make sure there aren't any cleaner way of defining padding when using drawText?
    No, there is no cleaner way. And changing the rect is the directest approach. So its the best and fastest.

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

    invictus (24th July 2009)

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.