[Interest] Determining if a glyph can be painted for a given character

Adam Light aclight at gmail.com
Thu Jun 25 18:17:22 CEST 2015


Our application has a QPlainTextEdit subclass, and one of its features is
that it has an option to display whitespace (such as line endings). One of
the whitespace symbols we use is \u21b5 (that's

Our current code reimplements QPlainTextEdit::paintEvent() and has code
like this:

QPainter painter(viewport());

const QChar CRGlyph((ushort)0x21b5);
QRawFont rf(QRawFont::fromFont(painter.font()));
const bool fontHasCRGlyph = rf.supportsCharacter(CRGlyph);

We only try to paint the whitespace character if fontHasCRGlyph is true,
since otherwise we would end up painting the empty rectangle that indicates
a character was not found, and that doesn't look good.

The problem is that on some platforms, including Windows 7 and Mac OSX
10.10, but not Mac OSX 10.9, fontHasCRGlyph is false. Yet, if I do
something simple like the following, the correct glyph for the same
character is displayed:

I suspect the reason for this is that the font in use by the QPlainTextEdit
does not contain the CRGlyph character, but a fallback font is available
for use that does contain the character, so it is displayed properly.
However, I initialize the QRawFont object with the primary font used in the
widget, which is lacking the glyph.

Does anyone have any suggestions of how I can test that a character can be
displayed correctly before I try to draw the character on screen?

Thanks for your help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150625/ae6f2518/attachment.html>

More information about the Interest mailing list