Search code examples
qtfilloutlinedrawtext

Qt 5.6, how to draw text with a different fill and outline colours


I'm using Qt5.6, I am drawing text on a video window, however sometimes the text is not very readable due to the video content in the window. I'm current drawing the text on the painter context with the 'drawText' method. Whilst I can set the pen colour which controls the fill, I do not seem to be able to set an outline colour.

I would like to draw the text with a black outline to make it stand out. Unfortunately firewall where I am working makes life very difficult and any useful web-site that might help, seems to be blocked, hence this post.

Thank you,


Solution

  • Try using QPainterPath::addText().

    You can add the text to a path, then QPainter::fillPath() and QPainter::strokePath() the path.

    Or you can direcly use QPainter::drawPath() with a brush and pen set.