在自定义场景中创建动态对象
使用QT Designer创建一个简单的GUI,可以执行附件图像中显示的内容。
即:单击LMB后,将标记放在点击位置,指示多边形的开始。然后,所需类型的临时多边形(但尺寸不同)开始遵循鼠标光标,直到我们再次单击LMB为止。之后,最终的多边形将从LMB的第一次点击点开始构建,再到第二次点击点。
这种现成的多边形必须存储在记忆中的某个地方,以进行进一步的工作。
作为一个多边形的多边形,我显示了一个基于某些计算的点建立的复杂扇区,但是简单的例子,您可以采取直线 - 我认为程序的本质不会发生太大变化。
我已经研究了许多在qgraphicsscene上不同事物实现的示例,但是我无法确切地弄清楚如何以所需的方式创建对象。也就是说,我知道我们需要一个单独的类,描述多边形并计算其组成的坐标,但我不太了解如何实现动态 - 每个mousemoveevent
,删除临时性多边形,为新坐标画一个新的,还是如何?
另外,我将如何实施重新定义的油漆类别,取代标准Qgraphicsscene类并从中继承的含义?
我面临这样一个事实,即在创建场景对象的自定义类时,单击附加的对象被程序忽略了,例如,在单击它时,它在场景上拖动对象,而是<代码>场景的MousePressEvent 而不是对象是触发的,我不明白问题是什么。
How it is possible using Qt Designer to create a simple GUI that performs what is shown in the attached image.
Namely: after a single click of the LMB, a marker is placed at the place of the click, indicating the beginning of the polygon. Then a temporary polygon of the desired type (but of different sizes) begins to follow the mouse cursor until we click on the LMB again. After which, the final polygon will be built from the point of the first click of the LMB to the point of the second click.
Such a ready-made polygon will have to be stored somewhere in memory for further work with it.
As a polygon here, I show a complex sector built on some calculated points, but as a simple example, you can take a straight line — I don't think that the essence of the program changes much.
I have already looked at many examples of different implementations of different things on QGraphicsScene, but I could not figure out exactly how to create an object in the way I needed. That is, I know that we need a separate class describing the polygon and calculating the coordinates of which it consists, but I don't quite understand how to implement the dynamics — with each mouseMoveEvent
, delete the temporary polygon, and draw a new one for the new coordinates, or how?
Also, how would I implement what was conceived through the redefined paintScene class, replacing the standard QGraphicsScene class and inheriting from it?
I am faced with the fact that when creating a custom class of the scene object, clicking on the objects attached to it is ignored by the program, and instead of, for example, dragging an object on the scene when clicking on it, the mousePressEvent
of the scene, not the object, is triggered, and I do not understand what the problem is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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