PDA

View Full Version : How to show Unicode characters on MS Windows?



quique
29th March 2012, 07:57
I need to show Unicode characters in a QLabel. This code works fine on Debian, but on Windows I just get a square.
FWIW, the browser does show this character when used in a webpage, and I can copy/paste it in Wordpad, so I guess it's not a font issue.
What am I missing?


#include <QtGui/QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QLabel label(QChar(10269)); // ⠝ (U+281D) is points 1,3,4,5 in Braille
label.show();

return app.exec();
}

Surendil
29th March 2012, 08:40
Hi, I think this is font issue, try to install Dejavu Sans and set font using

label.setFont(QFont("Dejavu Sans"));

quique
29th March 2012, 08:59
Hi, I think this is font issue, try to install Dejavu Sans and set font using

label.setFont(QFont("Dejavu Sans"));

Oh, that works!! Thanks! :-)

Should I just add that line as is, or should it only apply to the Windows build?
In the latter case, what would be the correct method to do it?

Surendil
29th March 2012, 12:04
Hmm I think it would be better to apply this only to Windows build (you said in Linux it works well). You may wrap this code with:

#ifdef Q_OS_WIN32
label.setFont(QFont("Dejavu Sans"));
#endif
Look at QtGlobal for platform preprocessor definitions and don't forget to include Dejavu (or any other font you want use for Braille) into your distribution package for Windows.

quique
29th March 2012, 16:39
Thanks for your pointer :)


don't forget to include Dejavu (or any other font you want use for Braille) into your distribution package for Windows.

That must be done in the installer, right?
I just began developing my app, and didn't explore yet the available options (Nullsoft Scriptable Install System, Inno Setup, WiX...).

ChrisW67
29th March 2012, 23:56
I believe that Windows 7 includes Braille characters in its Segoe UI Symbol font, but that earlier versions do not. So you have some Windows versions that require a third party font, and others that don't :( There are some free fonts containing just the Braille patterns: http://www.alanwood.net/unicode/fonts_windows.html#braillepatterns

quique
30th March 2012, 08:01
I believe that Windows 7 includes Braille characters in its Segoe UI Symbol font, but that earlier versions do not. So you have some Windows versions that require a third party font, and others that don't :(
Thanks for your comment.
DejaVu Sans is actually doing the trick (tested on both Windows 7 and Windows XP).