- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有没有办法在 Qt 5 中绘制带有小数点大小的文本。我正在尝试使用 QFont::setPointSizeF()
但它似乎在我尝试过的任何平台(mac/linux/windows)上都不起作用,并且点大小总是四舍五入。
QFontDatabase::isScalable
和 QFontDatabase::isSmoothlyScalable
在所有情况下都为字体返回 true
。
我尝试设置各种QFont::fontHintingPreference
和QPainter::RenderHint
。
我可以使用 QFont::setPixelSize
和 QPainter::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/
我在使用 QPainter 绘制不同颜色的线条和文本时遇到问题。我正在使用以下代码来实现此目的,但它不起作用。线条和文本都是使用绘制文本的颜色集绘制的。 void MyWidget::drawHorL
我正在尝试使用 QPainter(QT5.8,win64)绘制一个带有多个孔的多边形。我正在使用以下代码: QPainter pm(&image); QPen p(Qt::gray, 2); p.se
我要做什么 –对Qt编写的共享库进行JNI调用。在C++方面,我正在使用QPainter和QSvgRender来处理svg图像并返回一个简单的QImage。 QImage im; QPainter p
我有一些需要大量绘画的饼形小部件。所以我想在 QPainter 在 PaintEvent 中绘制后对其进行缓存。并稍后重用它。有没有直接或黑客的方法来做到这一点? 最佳答案 使用QPixmap作为缓存
是否有机会找出QPainter的大小?我正在使用 QPainter 来绘制移动应用程序的整个图形界面。问题是某些应用程序在窗口上覆盖了每个设备大小不同的菜单,从而使事情几乎不可能!是否有可能在不知道
上下文 我有一个自定义小部件,它应该制作点移动的动画,以便制作一种加载小部件。为了实现这个目标,我开始使用 QPainter 和 QVariantAnimation 对象,这似乎是完成这项工作的不错的
我有一个自定义的 QQuickPaintedItem,它可以绘制用户用鼠标在其上绘制的任何内容。到目前为止,实现非常简单,只需绘制整个图像,即使在放大时也是如此。我注意到放大和平移图像时 FPS 真的
我正在尝试在具有白色背景的 QFrame 上绘制两个具有相同颜色和透明度的矩形。这些矩形应该重叠并且它们的透明度不应该改变(也在重叠区域)。所以像这样: 这是我目前的代码: class Canvas
我有下面的代码通过QPainter显示一些文本 QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); paint
我使用下面的代码在qt中绘制一个图的轴: ... static const std::array horizontalAxis = { QPointF(0.f,0.f), QPointF(1.
我想在整个圆圈周围绘制那些黑点,彼此之间有规则的间距(下图的粗略图)。那些黑点应该直接坐在圆圈上。有没有一种简单的方法可以用 painter.drawArc() 函数或类似的东西来做这件事? 最佳答案
我正在学习 Qt。我没有意识到 the exercise of chapter 11 of Qt tutorial ,上面写着“当炮弹在空中时改变大炮的颜色”。我选择在 paintCannon 函数中
我创建了一个名为 painter 的类,并在将 QMainWindow 作为参数传递的构造函数中创建了 QPainter p。 所以在 mainwindow.h 中我添加了: protected:
我是Qt初学者,想用QPainter。 我的流程是这样的:我从串口接收数据坐标(x,y),比如(1,1), (2,3),等。我想在每次收到数据时在窗口中绘制这些点。 我看到 QPainter 在事件中
我有一个 QWidget,我在其中使用 QPainter 对象绘制一些点,但是当调用 update() 方法时,QWidget 的绘制被完全清除。有什么方法可以保存实际状态并只添加点,或者我必须保存每
这是我第一次使用 Qt,我必须制作一个与 Qt 等效的 MSPaint。然而,我在画线时遇到了麻烦。我目前可以通过单击屏幕上的某处并在其他地方释放来绘制一条线,但是当我绘制第二条线时,前一条线将被删除
以下代码会导致一堆错误: void MainWindow::displayBoard() { QPixmap pix(0,0); pix.fill(Qt::white); QP
我对书中示例和我的版本之间的差异感到困惑。Qt 版本 5.12.0 如示例所示: 从我的输出中可以看出: 首先,目标和源 In/Atop 模式的图片不同。而且,另一件值得注意的事情是,我们可以将矩形视
问题很简单!我想要这样的东西。要么使用 QPainter类或使用 Qt 图形框架 : 最佳答案 有几种方法可以使用 QPainterPath 来做到这一点。指定 here . 这是该页面的第二个示例:
默认情况下,QPainter 的原点位于左上角。我想绘制形状,但我拥有的所有坐标都在笛卡尔系统中。所以我的问题 - 如何将原点更改为左下角?当然,我可以 scale(1,-1) 但 drawText(
我是一名优秀的程序员,十分优秀!