侧边栏壁纸
博主头像
三味的小站博主等级

世界上没有偶然,有的只是必然的结果。

  • 累计撰写 61 篇文章
  • 累计创建 13 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录
Qt

QGraphicsTextItem旋转后字体加粗无效问题

三味线
2023-08-14 / 0 评论 / 0 点赞 / 21 阅读 / 13838 字

同样的字体设置,item旋转后字体加粗无效,但是放大视图,会发现垂直的文字又加粗了

多番查找后发现将字形提示优先级设为无可以解决

mFont.setHintingPreference(QFont::PreferNoHinting);

暂不清楚具体原理,大概是水平、垂直的字形渲染差异,以下截自帮助文档:

enum QFont::HintingPreference

This enum describes the different levels of hinting that can be applied to glyphs to improve legibility on displays where it might be warranted by the density of pixels.

Constant

Value

Description

QFont::PreferDefaultHinting

0

Use the default hinting level for the target platform.

QFont::PreferNoHinting

1

If possible, render text without hinting the outlines of the glyphs. The text layout will be typographically accurate and scalable, using the same metrics as are used e.g. when printing.

QFont::PreferVerticalHinting

2

If possible, render text with no horizontal hinting, but align glyphs to the pixel grid in the vertical direction. The text will appear crisper on displays where the density is too low to give an accurate rendering of the glyphs. But since the horizontal metrics of the glyphs are unhinted, the text's layout will be scalable to higher density devices (such as printers) without impacting details such as line breaks.

QFont::PreferFullHinting

3

If possible, render text with hinting in both horizontal and vertical directions. The text will be altered to optimize legibility on the target device, but since the metrics will depend on the target size of the text, the positions of glyphs, line breaks, and other typographical detail will not scale, meaning that a text layout may look different on devices with different pixel densities.

Please note that this enum only describes a preference, as the full range of hinting levels are not supported on all of Qt's supported platforms. The following table details the effect of a given hinting preference on a selected set of target platforms.

PreferDefaultHinting

PreferNoHinting

PreferVerticalHinting

PreferFullHinting

Windows Vista (w/o Platform Update) and earlier

Full hinting

Full hinting

Full hinting

Full hinting

Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt

Full hinting

Vertical hinting

Vertical hinting

Full hinting

FreeType

Operating System setting

No hinting

Vertical hinting (light)

Full hinting

Cocoa on macOS

No hinting

No hinting

No hinting

No hinting

Note: Please be aware that altering the hinting preference on Windows is available through the DirectWrite font engine. This is available on Windows Vista after installing the platform update, and on Windows 7. In order to use this extension, configure Qt using -directwrite. The target application will then depend on the availability of DirectWrite on the target system.

This enum was introduced or modified in Qt 4.8.

0

评论区