QPainter.drawText and margin/padding
Hi
I have a QRectF defined for drawing a rect and draw text inside of this visible rect.
Code:
painter.fillRect(rect, bgColor);
painter.
drawText(rect, Qt
::AlignRight,
QString("A string"));
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.
Re: QPainter.drawText and margin/padding
Quote:
Originally Posted by
invictus
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.