如何合并 QPainterPaths

发布于 2024-12-28 06:12:49 字数 173 浏览 3 评论 0原文

我需要将两个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

会发光的星星闪亮亮i 2025-01-04 06:12:49

我想说,如果您还没有尝试过,那么 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 maybe subtracted(QPainterPath), or intersected(QPainterPath), depending on what you try to achieve.

Could you please give us more details about what you've tried so far?

风柔一江水 2025-01-04 06:12:49

首先使用重载的 + 运算符合并路径,然后对其调用 simplified() 可能会有所帮助。 QPainterPath 参考

至少当我有两条路径时解决了我的问题两个正方形有一条共同边,如果不调用 simplified(),它仍然是两个正方形,但如预期那样,它会是一个矩形。

It might help to first merge the paths using the overloaded + operator and then call simplified() on it. QPainterPath reference

At 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.

笑咖 2025-01-04 06:12:49

如果从两个路径 p1 和 p2 开始,每个路径包含一个子路径,则:

joined = p1.toSubpathPolygons()[0] + p2.toSubpathPolygons()[0]
p3 = QPainterPath()
p3.addPolygon(joined)

您还可以使用 path.toReversed() 更改每个路径的连接方向。
(抱歉,这是 python 语法,但对于 C++ 应该几乎相同)

If you start with two paths p1 and p2, each containing a single subpath, then:

joined = p1.toSubpathPolygons()[0] + p2.toSubpathPolygons()[0]
p3 = QPainterPath()
p3.addPolygon(joined)

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++)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文