坐标缩放导致QPainter :: drawText中的字体太大 [英] Coordinate scaling causes too large font sizes in QPainter::drawText

查看:542
本文介绍了坐标缩放导致QPainter :: drawText中的字体太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

那部分在我的可视化窗口小部件上效果很好.碰巧是个问题,就是写了应该代表每个分子ID(整数)的文本.

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()));

它绘制文本,但是太大.这可能是因为我需要对myPainter使用色原缩放以轻松绘制分子.

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_

我尝试在myPainter中执行缩放协调之前放置这样的行:

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.

在此先感谢您的帮助.

推荐答案

记住要在其上绘制文本的位置,然后分两个阶段进行绘制.第一个是分子,第二个是分子.在绘制分子之前,请保存绘制器的状态,并在绘制文本之前将其还原.这应该防止文本缩放,同时允许缩放分子.

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.

这篇关于坐标缩放导致QPainter :: drawText中的字体太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆