QML 和 c++ 代码使用相同的字体。
QML:
TextEdit {
...
font: settings.font // font.preferShaping = false doesn't help
...
renderType: Text.QtRendering // Text.NativeRendering also doesn't paint correctly
}
字母(圆角):
C++:
QSGNode* Text::updatePaintNode(QSGNode* oldNode, QQuickItem::UpdatePaintNodeData*)
{
...
QImage image(QSize(size, QImage::Format_ARGB32_Premultiplied);
QPainter painter(&image);
//painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); doesn't help also
image.fill(QColor(0, 0, 0, 0));
painter.setFont(settings.font());
painter.drawText(rect, alignment(), text));
...
}
字母(尖角):
更新: 下面的代码也没有修复 QML 中的角:
font.family: "Segoe UI"
font.pixelSize: 15
font.preferShaping: false
如何同步 QML 和 C++ 之间的字体外观?