文本未出现在QT中的指定位置
我有一个qgraphicsview
,其中包含许多qgraphicSitem
,例如矩形,polylines等。 我想命名每个矩形,名称在矩形上。
名称应集中对齐,即字符串名称字符的一半应为中位置的一侧,一半的字符应为中位置的右侧。
为此,我使用了以下psuedo代码:
int firstPosition = GetMidPosition () - (strLength / 2);
int secondPosition = some points
DrawText( firstPosition , secondPosition );
现在,如果我打印第一位置,二位置,getmidposition()的坐标,它们会像我期望的那样完美。
但是,文本不正确。我必须手动调整它。
int firstPosition = GetMidPosition () - 6 *(strLength / 2);
现在看起来是集中的。为什么会发生这种情况?坐标是正确的,那么为什么我必须手动调整它。
我想避免进行调整(即6 *)
如果明天,我更改了文本的字体大小,那么我将不得不 将乘法因子6更改为其他东西。那应该 没有发生。如何为此编写通用逻辑?
I have a QGraphicsView
which contains many QGraphicsItem
like rectangle, polylines etc.
I want to name each rectangle and name is on the rectangle.
Name should be centrally aligned i.e. half of the string name characters should be left side of mid position and half of the characters should be right side of mid position.
For that I used following psuedo code:
int firstPosition = GetMidPosition () - (strLength / 2);
int secondPosition = some points
DrawText( firstPosition , secondPosition );
Now if I print co-ordinates of firstPosition, secondPosition , GetMidPosition() they comes perfectly as I expect.
But, the text does not come properly. I have to manually adjust it.
int firstPosition = GetMidPosition () - 6 *(strLength / 2);
Now it appears centrally. Why this is happening ? Co-ordinates are correct then why I have to manually adjust it.
I want to avoid that adjustment (i.e. 6 * )
If tomorrow, I changed the font size of text, then I will have to
change the multiplication factor 6 into something else. That should
not be happened. How to write general purpose logic for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论