开发者

qpainterpath.addtext ignores qfont weight

Using Qt 4.7.0, we need some text to display part way between normal and bold. Here's what we're doing:

In the Paint method of our subclass of QGraphicsObject, we have a QFont that we call setWeight(58) on. We create a QPainterPath and call its addText method, passing in our QFont.

We then use the QPainter parameter to call drawPath, passing in our QPainterPath.

What we've found is changes in fontweight from 开发者_如何学C50 to 62 make no difference in how it is painted. With a fontweight of 63 to 75, the font is painted bold.

How can we get the fontWeight to work as we expect?


Per the documentation:

Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration.

The W3C page on CSS font boldness has a good explanation of how CSS handles it; the Qt documentation says it is doing something similar. Basically, it applies some heuristic to try to map your weight value to the appropriate version of the font (regular, bold, heavy, etc.)

It may be possible (perhaps outlining a QPainterPath?) to create slightly-thicker-than-normal glyphs of a certain font, but the results are almost certainly going to be disappointing. Font designers put a lot of effort into making fonts look good at certain weights. When you depart from that (say, by outlining each glyph), all that design optimization is lost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜