QPainterPath closed shape is possible?
-
Hi,
Currently I am working on a basic graphics editor. As part of my requirements, I am trying to figure out if there is a way to create a QPainterPath (irregular) shape where the first point and the last point are a unique same value inside the path structure.I was trying to use the path.lineTo() method, but finally I always get two points with the same coords, but my problem is that I am working on a "nodes" editor tool too, so when I try to edit the key points of the shape, I always can open the shape by separating the first and the last point. My goal is that when I am editing any closed path, the first and the last point behave like one. Think of an ellipse or rectangle, I need a similar behavior.
Any suggestion? Thanks!
-
@xtingray
Hello,
Have you tried explicitly closing the path? -
@kshegunov In fact, I already tried it too but I can keep "reopening" the shape if I edit it. I was thinking of it and I guess that is impossible to actually close a path as I need to, because you always will need to repeat the value of the first point in the last point to create the illusion of a closed path, but behind you always will have two different points (with the same value) within the path data structure.
Maybe the trick I will try is this: every time I select a shape, I will check if first point == last point, then that path is officially closed, so, if I move first point to somewhere else, then I move last point too (same action applies if I try to move the last point). Just guessing.
-
@xtingray
Okay, this might work. But why are you usingQPainterPath
for the "logic" (assuming you have straight lines). You could keep a polygon, make the changes to it, and in the paint event usedrawPolygon
or convert it to a closed path and eventually draw it? -
@kshegunov I am working on a drawing tool, so most of the objects are irregular/curves, like in any hand-made illustration. Using polygons will make my logic more complex and a little out of context. Working with QPainterPath objects directly, the result is very acceptable.
I just wanted to implement the "closed path" feature without getting in trouble, just that, because I thought I was missing some kind of specific QPainterPath method, but it seems is not the case. -
@xtingray said:
I am working on a drawing tool, so most of the objects are irregular/curves, like in any hand-made illustration.
I see, so you're actually not using straight lines, which explains why a polygon isn't a good option.
I just wanted to implement the "closed path" feature without getting in trouble, just that, because I thought I was missing some kind of specific QPainterPath method, but it seems is not the case.
Not to my knowledge, no. A painter path can be quite complex and have multiple subpaths in it (some closed, some not) which makes it a bit burdensome, for a lack of better description, to work with. Unfortunately, nothing better comes to mind.