坐标缩放导致 QPainter::drawText 中的字体太大

发布于 2024-09-27 22:24:35 字数 772 浏览 2 评论 0原文

我正在为 MD 模拟代码开发简单的 2D 可视化模块。我想做的是使用以下方法绘制模拟分子的位置:

myPainter.drawEllipse(myQPoint,myRx,myRy)

并且该部分在我的可视化小部件上运行得很好。碰巧出现的问题是编写代表每个分子 ID(整数)的文本。

myPainter.drawText(myPosPoint,QString::number(mySoftMolecule2D->getID()));

它绘制文本,但太大。这可能是因为我需要使用 myPainter 的坐标缩放来轻松绘制分子。

myPainter.scale(myWidgetWidth_ / simSizeX_ , myWidgetHeight_ / simSizeY_);
//    myWidgetWidth_ is much bigger simSizeX_
//    myWidgetHeight_ is much bigger simSizeY_

我尝试在 myPainter 中执行缩放坐标之前放置这样的线:

QFont myFont;
myFont.setPointSizeF(1.0); // values less than 1.0 doesn't work
myFont.setFamily("Courier");
myPainter.setFont(myFont);

但分子的标签仍然太大。

预先感谢您的任何帮助。

I'm working on simple 2D visualization module for MD simulation code. What I'm trying to do is drawing positions of simulated molecules using:

myPainter.drawEllipse(myQPoint,myRx,myRy)

And that part works pretty good on my visualization widget. The thing that happened to be a problem is writing text which should represent each molecule's ID (integer).

myPainter.drawText(myPosPoint,QString::number(mySoftMolecule2D->getID()));

It draws text but it is too large. This is probably because I need to use cooridantes scaling for myPainter to draw molecules easily.

myPainter.scale(myWidgetWidth_ / simSizeX_ , myWidgetHeight_ / simSizeY_);
//    myWidgetWidth_ is much bigger simSizeX_
//    myWidgetHeight_ is much bigger simSizeY_

I tried putting such lines before I perform scaling cooridnates in myPainter:

QFont myFont;
myFont.setPointSizeF(1.0); // values less than 1.0 doesn't work
myFont.setFamily("Courier");
myPainter.setFont(myFont);

but the molecules' label are still much too big.

Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦太阳 2024-10-04 22:24:35

由于您想根据固定像素大小调整字体大小,请尝试使用 QFont:: setPixelSize(int PixelSize) 而不是 setPointSize()

Since you want to size a font based on a fixed pixel size, try using QFont::setPixelSize(int pixelSize) instead of setPointSize().

少女七分熟 2024-10-04 22:24:35

记住要绘制文本的位置,然后分两个阶段进行绘制。第一个是分子,第二个是文本。在绘制分子之前,保存画家的状态,并在绘制文本之前恢复它。这应该可以防止文本缩放,同时允许缩放分子。

Remember the positions you want to draw the text at, then draw in two stages. The first is the molecules, the second the text. Before drawing the molecules, save the state of the painter, and restore it before drawing the text. This should prevent scaling of the text while allowing the molecules to be scaled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文