Qt4 QGraphicsView:如何在浮动位置设置 QPen
我有一个带有图像和自定义光标的 QGraphicsView。光标由两条 QPen-DotLine 组成。 x 轴 dotLine 和 y 轴 dotLine。两条线的交叉点就是鼠标光标的位置。问题是,当我放大时,十字不再位于鼠标光标位置下方。例如,当鼠标光标的值为 x = 1.4235 ans y = 2.7732 然后将点线设置在位置 x = 1 和 y = 2 上。但我希望将点线设置在浮动位置上(x = 1.4235 ans y = 2.7732)。我该怎么办呢。
我得到的鼠标位置
def mouseMoveEvent(self,event):
...
... self.grview.mapToScene(event.pos())
...
和我用 setPos() 设置的点线。 我认为 setPos() 将 float 转换为 int。但我不知道如何解决。希望你们中有人有一个有用的想法。
I've a QGraphicsView with an image and a custom cursor. The cursor is made out of two QPen-DotLines. A x-axis dotLine and a y-axis dotLine. The cross of the two lines is the mouse-cursor position. The problem, when I zoom in, the cross is not more under the mouse-cursor position. For example, when the values of the mouse-cursor are x = 1.4235 ans y = 2.7732
then the dotLines are set on the position x = 1 and y = 2. But I want to have the dotLines on the float position (x = 1.4235 ans y = 2.7732). How can I do that.
Mouse position I get with
def mouseMoveEvent(self,event):
...
... self.grview.mapToScene(event.pos())
...
and the dotLines I set with setPos().
I think setPos() converts float to int. But I don't know how to work around. Hope someone of you has an helpful idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题。之前实现了一些代码的人使用了“drawEllipse (int x, int y, int width, int height)”,这将 float 转换为 int。所以我唯一要做的就是将其替换为“drawEllipse ( const QPointF & center, qreal rx, qreal ry )”。
抱歉给您带来麻烦并谢谢您。
I found the problem. The guy who implemented some of the code before used "drawEllipse ( int x, int y, int width, int height )" and this converts float to int. So the only thing I had to do is to replace it with "drawEllipse ( const QPointF & center, qreal rx, qreal ry )".
Sorry for the trouble and thank you.