I have a QLineEdit where user will enter a name (not necessary a human name) and the character is not rendered. It looks like:
How do I have to configure the QLineEdit encoding to get that character visible?
It looks that the solution is quite simple. It is needed to upgrade to Qt 5.5.1.
The symbol is also correctly displayed in the editor of Qt Creator 3.5.1 that is based on Qt 5.5.1. In Qt Creator 3.2.1 (based on Qt 5.3.2) the symbol is not displayed.
The symbol is displayed as rectangle in UI controls of Qt 5.3.2. However, it is correctly displayed in labels and in other text controls if the project is built by Qt 5.5.1.
It appears that at least Qt 5.5.1 is needed to find such character if it is not present in the default font of the UI control.
The default font fall back mechanism is implemented only in Qt 5.5.1, so even Q 5.5.0 cannot properly display the character if it is not found in the selected font.
I guess that the improvement is done by the Qt commit 5e3e34731b7880ac775e8f1fa156ce016e6820f1 Default implementation for QPlatformFontDatabase::fallbacksForFamily() (maybe in connection with previous [QFontDatabase] Defer the fallback families list initialization).
However, it is still possible to display that character in older Qt versions (even in Qt4). It possible to set manually font that supports needed symbols.
For example, there is font "SimSun-ExtB" in Windows that supports CJK Unified Ideographs Extension B. That font can be set manually to specific UI widgets or to the entire application:
QFont CJK_ExtB("SimSun-ExtB");
// font for widget
ui->lineEdit->setFont(CJK_ExtB);
// or default application font
QApplication::setFont(CJK_ExtB);
Of course to display a character it should be available in some system font or in application loaded font. Windows 7 by default has font for CJK Ext.B
, but to display symbols from CJK-C
or CJK-D
some other font is needed. For example, there is a free Unicode CJK font BabelStone Han that covers some such symbols. It is possible to load it manually for application:
QFontDatabase::addApplicationFont("c:/test/BabelStoneHan.ttf");
Now the application is able to find automatically CJK-B
symbols in Windows system font "SimSun-ExtB" and CJK-C
symbols in "BabelStoneHan" if Qt 5.5.1 is used.
The font fallback improvement in Qt 5.5.1 mainly affects Windows, since in Ubuntu Linux the application is able to find proper fonts for symbols even with older Qt versions (if fonts are added by QFontDatabase::addApplicationFont
, since there is no system fonts for CJK extensions by default).