QLineEdit Japanese / Chinese character 𤭢 not displayed

I have a QLineEdit where the user enters a name (not necessarily the person's name) and the character is not displayed. It looks like this:

enter image description here

How do I tune the encoding of QLineEdit to get this character?

+3


source to share


1 answer


It looks like the solution is pretty simple. You need to upgrade to Qt 5.5.1.

The symbol is also displayed correctly in the Qt Creator 3.5.1 editor 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 a rectangle in Qt user interface controls 5.3.2. However, it appears correctly in labels and other text controls if the project is built with Qt 5.5.1.


It looks like it requires at least Qt 5.5.1 to find such a character if it is not present in the standard font of the UI control.

The default font reduction mechanism is only implemented in Qt 5.5.1, so even Q 5.5.0 cannot display a character correctly if it is not found in the selected font.

I assume the improvement is made with Qt commit 5e3e34731b7880ac775e8f1fa156ce016e6820f1 Default implementation for QPlatformFontDatabase :: fallbacksForFamily () (possibly related to previous [QFontDatabase] Defer initialization of fallback families list ).


However, it is still possible to display this symbol in earlier versions of Qt (even in Qt4). You can install a manual font that supports the characters you want.



For example, there is a "SimSun-ExtB" font in Windows that supports the Unified Ideographs CJK B extension. This font can be manually installed for specific UI widgets or for 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 symbol, it must be available in some system font or in a downloaded application font. Windows 7 has a default font for CJK Ext.B

, but a different font is needed to display characters from CJK-C

or CJK-D

. For example, there is a free Unicode font CJK BabelStone Han that covers some of these characters. It can be manually downloaded for use:

QFontDatabase::addApplicationFont("c:/test/BabelStoneHan.ttf");

      

Now the application can automatically find symbols CJK-B

in the Windows system font "SimSun-VvB" and CJK-C

symbols in "BabelStoneHan" if using Qt 5.5.1.


Improving the font fallback in Qt 5.5.1 mainly affects Windows, as in Ubuntu Linux the application can find the correct fonts for symbols even with older versions of Qt (if fonts are added QFontDatabase::addApplicationFont

, as there is no default system fonts for CJK extensions).

+3


source







All Articles