Reputation: 71
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.
Upvotes: 4
Views: 2362
Reputation: 10859
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.
Upvotes: 2
Reputation: 11644
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++)
Upvotes: 1
Reputation: 396
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?
Upvotes: 2