[Qt-interest] QPainter::drawText - text outline vs text fill?

Girish Ramakrishnan girish at forwardbias.in
Sun May 1 12:07:55 CEST 2011


Hi,

On Fri, Apr 29, 2011 at 2:40 PM, Schimkowitsch Robert
<Robert.Schimkowitsch at andritz.com> wrote:
> When reading through the docs of the QGraphicsSimpleTextItem, I noticed the
> following sentence:
>
> "The simple text item can have both a fill and an outline; setBrush() will
> set the text fill (i.e., text color), and setPen() sets the pen that will be
> used to draw the text outline."
>
> (I remembered our trainer mentioned that in a QGraphicsView training course,
> too).
>
> Since I'll be mostly using QPainter::drawText directly, I was wondering how
> QPainter::drawText would behave in that respect. The online documentation
> says:
>
> (http://doc.qt.nokia.com/latest/qpainter.html)
> "The pen defines how to draw lines and outlines, and it also defines the
> text color. "
>
> Outline or fill? Or does QPainter not distinguish between those two?
>

QPainter::drawText always fills using the pen and it doesn't use the
brush. Note that a pen can be set a brush using the QPen(QBrush)
constructor.

When drawing text with outlines and fills, the text is converted into
a path which is stroked and filled. See
http://doc.qt.nokia.com/4.7-snapshot/qpainterpath.html#addText for how
the QGraphicsSimpleTextItem would do it.

Girish



More information about the Qt-interest-old mailing list