如何合并 QPainterPaths
我需要将两个QPainterPath
“合并”在一起。问题是它们似乎总是两条不同的道路。
我需要的是,合并实际上变得就像构建了一个单独的合并(来自复杂的多边形或一堆复杂的线)一样,没有任何内部线工件或子路径,因为它们之前是两条不同的路径。这似乎是一个非常简单和正常的任务,但我不知道如何去做。
I need to "merge" two QPainterPath
together. The problem is that they always seems to be two different paths.
What I need is that the merge really become the sames as if a single one ( from a complex polygon or a complex bunch of lines) had been constructed, without any inner line artifacts or subpath from the fact that they were two distinct paths previously. It seems a pretty simple and normal task but I can't figure how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想说,如果您还没有尝试过,那么
united(QPainterPath)
方法(QPainterPath 类)就是您正在寻找的方法。或者可能是subtracted(QPainterPath)
,或者intersected(QPainterPath)
,具体取决于您想要实现的目标。您能否向我们提供有关您迄今为止所尝试的更多详细信息?
I would say that the
united(QPainterPath)
method (QPainterPath class) is the one you are looking for, if you did not try it yet. Or maybesubtracted(QPainterPath)
, orintersected(QPainterPath)
, depending on what you try to achieve.Could you please give us more details about what you've tried so far?
首先使用重载的
+
运算符合并路径,然后对其调用simplified()
可能会有所帮助。 QPainterPath 参考至少当我有两条路径时解决了我的问题两个正方形有一条共同边,如果不调用
simplified()
,它仍然是两个正方形,但如预期那样,它会是一个矩形。It might help to first merge the paths using the overloaded
+
operator and then callsimplified()
on it. QPainterPath referenceAt least that solved the problem for me when I had two paths of two squares that had one edge in common and without a call to
simplified()
it would still be two squares but with it would be one rectangle as expected.如果从两个路径 p1 和 p2 开始,每个路径包含一个子路径,则:
您还可以使用 path.toReversed() 更改每个路径的连接方向。
(抱歉,这是 python 语法,但对于 C++ 应该几乎相同)
If you start with two paths p1 and p2, each containing a single subpath, then:
You can also change the direction that each path is joined by using path.toReversed().
(sorry, this is python syntax but should be nearly the same for C++)