View Full Version : QTextEdit shows unicode characters correctly, except on Windows

7th June 2012, 22:58
My application uses a custom QTextEdit subclass, and sometimes programmatically inserts unicode characters into it using code like this.

QChar c = QChar( unicodeCell, unicodeRow );
myQTextEditInstance->insertPlainText( c );

Because I want a wide variety of unicode characters to be available (specifically, lots of math symbols), I install all the DejaVu fonts with my app, and set DejaVu Serif as the default font on the QTextEdit in question. But I get different behavior on different platforms. Specifically, it works great everywhere but Windows (i.e. on Mac Lion and Ubuntu 12.04, Qt 4.8 in all cases). On Windows, instead of the characters that show up correctly on the other platforms, I get the dreaded empty rectangles.

So I did a little testing. I queried the QGlyphRuns and dumped their data to the console for debugging. Here are the results:

On Mac, it uses DejaVu Serif for most things (plain text and more common unicode symbols), but for some of the rarer unicode chars it uses the Apple Symbols font. All characters show up looking as expected.
On Linux, it uses DejaVu Serif for all characters, even the ones that Mac used Apple Symbols for. All characters show up looking as expected.
On Windows, it uses DejaVu Serif for all characters, just like Linux, BUT many of the rarer unicode symbols just display as boxes, not as the correct chars.

Now, you'd suspect that since the characters are in the font, as demonstrated by Linux, Windows would be able to find them. But in fact, Windows is not using the same characters (i.e., same glyph indices) as Linux. The glyph run output shows that Linux is choosing the correct glyph indices from the font to draw, while Windows is, for the problematic chars, using index 0 instead (the index of the box char?). May'be thats because it doesn't think the unicode char it needs is actually in the font? The font files are identical .ttf files used on all 3 platforms.

Furthermore, even the "Application Output" pane in Qt Creator on Windows does not dump the actual unicode chars in the qDebug() output, while that same pane on the other platforms do. I have not set Creator to use DejaVu fonts, but I'm just throwing this info in case it helps.

Any tips on why Windows doesn't think those chars are in the font, and how to get Windows to be able to draw those characters? Thank you!