如题,在
QPainter自绘的过程中,自己设置了第三方
字体,
中文的并没与设置成功,但英文和数字却设置成功了。
具体代码如下:
- //构造函数
-
- QStringList fontName = QFontDatabase::applicationFontFamilies(fontId);
- if (fontName.count() > 0)
- {
- iFont = QFont(fontName.at(0));// iFont私有成员
- }
- else
- {
- qDebug() << "load XenoisSansPro-Bold.ttf error";
- }
- //重绘
- void CustomRectangle::paintEvent(QPaintEvent *event)
- {
- Q_UNUSED(event);
- float percent = 0.612;
- QRectF rectangle(10.0, 20.0, 670.0, 26.0);
- painter.drawRect(rectangle);
- painter.fillRect(rectangle, QColor("#293140"));
- QRectF rectUsed(10.0, 20.0, 670.0*percent, 26.0);
- painter.fillRect(rectUsed, QColor("#2F88F0"));
- QRectF rectUnUsed(10.0 + 670.0*percent, 20.0, 670.0*(1-percent), 26.0);
- painter.fillRect(rectUnUsed, QColor(Qt::red));
- QFont font;
- font.setFamily("XenoisSansPro-Bold");
- font.setPixelSize(14);
- painter.setFont(font); //设置XenoisSansPro-Bold字体
- QPen pen;
- pen.setColor(QColor(Qt::white));
- painter.setPen(pen);
- QRectF rectText(10.0 + 10.0, 20.0, 670.0, 26.0);
- //XenoisSansPro-Bold字体数字和英文设置成功,中文字体未变
- painter.drawText(rectText, Qt::AlignLeft | Qt::AlignVCenter, QString("61.2 GB 已用/38.8 GB 可使用"));
- //XenoisSansPro-Bold字体设置成功
- //painter.drawText(rectText, Qt::AlignLeft | Qt::AlignVCenter, QString("61.2 GB Used/38.8 GB UnUsed"));
- }
如上,为什么有中文的时候,中文的字体
没有和英文或数字同意加载成为XenoisSansPro-Bold字体呢?
请问各位大佬们,为啥会有中文字体未设置成功呢?各位大佬们帮忙看看,给点意见,小弟在此多谢了!