简体   繁体   English

使用 C++ 在 Qt5 中显示曲线

[英]Show a curve in Qt5 using C++

Now, I have geometry information of some curves, which are given with the following format.现在,我有一些曲线的几何信息,这些信息以下列格式给出。

<LineString><coordinates>-43.276042355627,-32.8022614460173,0.0 -43.9683944443137,-31.9135623685828,0.0 -44.4979806584518,-31.1926527722131,0.0</coordinates></LineString>

I would like to show them in my scene.我想在我的场景中展示它们。 I know I can do this by creating multiple QGraphicsLineItem s one by one.我知道我可以通过一个一个地创建多个QGraphicsLineItem来做到这一点。 But is there any other easy way to do this, like one curve item?但是有没有其他简单的方法可以做到这一点,比如一个曲线项目?

You can use QGraphicsPathItem along with QPainterPath .您可以将QGraphicsPathItemQPainterPath一起使用。 Reimplement the QGraphicsPathItem , add a method that receives your original points.重新实现QGraphicsPathItem ,添加一个接收原始点的方法。 Create a QPainterPath and iterate over points.创建一个QPainterPath并遍历点。 Use moveTo on the first point and lineTo for the next points.在第一个点上使用moveTo ,在下一个点上使用lineTo Then call setPath of QGraphicsPathItem to redraw the new curve.然后调用QGraphicsPathItemsetPath重新绘制新曲线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM