gpt4 book ai didi

c++ - QPainter drawText 小数点

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:26:12 29 4
gpt4 key购买 nike

有没有办法在 Qt 5 中绘制带有小数点大小的文本。我正在尝试使用 QFont::setPointSizeF() 但它似乎在我尝试过的任何平台(mac/linux/windows)上都不起作用,并且点大小总是四舍五入。

QFontDatabase::isScalableQFontDatabase::isSmoothlyScalable 在所有情况下都为字体返回 true

我尝试设置各种QFont::fontHintingPreferenceQPainter::RenderHint

我可以使用 QFont::setPixelSizeQPainter::scale 来解决这个问题,但是 QFont::setPointSizeF 似乎很奇怪> 坏了?!

我是否遗漏了什么或做错了什么?

显示问题的简单程序:

#include <QtWidgets>

class MyWidget : public QWidget
{
public:
MyWidget() : QWidget(0)
{
}

protected:
void paintEvent(QPaintEvent */*e*/)
{
QPainter p(this);
int y=10;

for (qreal i = 10; i < 20; i += 0.2) {
QFont font("Times"); // or any font font in the system
font.setPointSizeF(i);
p.setFont(font);
p.drawText(1, y, QString("This should be point size %1 but is %2!").arg(font.pointSizeF()).arg(QFontInfo(font).pointSizeF()));
y += i;
}
}
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyWidget widget;
widget.resize(400, 740);
widget.show();
return app.exec();
}

最佳答案

这不是意外行为。请参阅以下行:

"This should be point size 10 but is 9.75!"
"This should be point size 10.2 but is 10.5!"
"This should be point size 10.4 but is 10.5!"
"This should be point size 10.6 but is 10.5!"
"This should be point size 10.8 but is 10.5!"
"This should be point size 11 but is 11.25!"
"This should be point size 11.2 but is 11.25!"
"This should be point size 11.4 but is 11.25!"
"This should be point size 11.6 but is 11.25!"
"This should be point size 11.8 but is 12!"
"This should be point size 12 but is 12!"
"This should be point size 12.2 but is 12!"
...

然后,还要检查文档:

将磅值设置为 pointSize。磅值必须大于零。可能无法在所有平台上实现请求的精度。

关于c++ - QPainter drawText 小数点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19036047/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com