Reputation: 11
When I use underline to a button text that include Chinese and English, and use English font family, the underline can't display completely. The use of Qt-Designer can show this phenomenon too.
This is a button in Qt Designer, font family is Arial.
I don't know why and how to solve this. Any one has good idea?
Upvotes: 1
Views: 1522
Reputation: 20141
I started with an MCVE because I was curious whether I could reproduce your issue on my side (Window 10 – 64 Bit).
So, this is testQPushButtonUnderline.cc
:
// Qt header:
#include <QtWidgets>
int main(int argc, char **argv)
{
qDebug() << QT_VERSION_STR;
// main application
QApplication app(argc, argv);
// setup GUI
const QString qTxt(
QString::fromUtf8("\xe4\xb8\xad\xe6\x96\x87""English"));
QPushButton qBtn(qTxt);
QFont qFont = qBtn.font();
qFont.setUnderline(true);
qBtn.setFont(qFont);
qBtn.show();
// run application
return app.exec();
}
Compiled and tested in VS2013:
Ouch! I must admit that I didn't expect it. So, I started investigation with other widgets (QLabel
, QTextEdit
):
As already expected, it seems to be the "Qt Rich Text Rendering Engine" which is somehow broken. (It looks like the Chinese glyphs are not considered in the layouted underlining.)
I believe this is something which might be reported as bug to The Qt Company.
I thought a bit about how the rendering engine might ensure that the default font (in my case – Qt default settings, Windows 10 default settings) contains the necessary glyphs. What if they have to switch somewhere "under the hood" to get all necessary glyphs whereby some bug affects rendering errors. Speculations, speculations...
However, this brought me to the idea to provide a font which definitely has the needed glyphs. I searched one in the Windows charmap
utility (which I always have at hand at my taskbar) and found Microsoft JhengHei
.
The updated testQPushButton.cc
:
// Qt header:
#include <QtWidgets>
int main(int argc, char **argv)
{
qDebug() << QT_VERSION_STR;
// main application
QApplication app(argc, argv);
// setup GUI
const QString qTxt(
QString::fromUtf8("\xe4\xb8\xad\xe6\x96\x87""English"));
QPushButton qBtn(qTxt);
QFont qFont = qBtn.font();
qFont.setFamily(QString::fromLatin1("Microsoft JhengHei"));
qFont.setUnderline(true);
qBtn.setFont(qFont);
qBtn.show();
// run application
return app.exec();
}
compiled and tested (in VS2013 again):
Hah!
Out of curiosity, I tried to reproduce this issue in cygwin. (The Qt libraries in my cygwin are installed with the cygwin setup. In VS2013, I used Qt libraries instead compiled by a co-laborator for our professional work. It's pure accidence that they have identical version.)
$ cat >testQPushButtonUnderline.pro <<'EOF'
> SOURCES = testQPushButtonUnderline.cc
>
> QT += widgets
> EOF
$ qmake-qt5 testQPushButtonUnderline.pro
$ make
g++ -c -fno-keep-inline-dllexport -D_GNU_SOURCE -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtCore -I. -I/usr/lib/qt5/mkspecs/cygwin-g++ -o testQPushButtonUnderline.o testQPushButtonUnderline.cc
g++ -o testQPushButtonUnderline.exe testQPushButtonUnderline.o -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
$ ./testQPushButtonUnderline
5.9.2
Btw. in cygwin it looked exactly the same with my above fix. I didn't care about this as the Microsoft JhengHei
is probably not found in the X11 system of cygwin and hence ignored.
Upvotes: 1