Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QPainterPath closed shape is possible?

    General and Desktop
    2
    6
    1586
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xtingray last edited by

      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!


      Qt Developer

      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @xtingray last edited by

        @xtingray
        Hello,
        Have you tried explicitly closing the path?

        Read and abide by the Qt Code of Conduct

        X 1 Reply Last reply Reply Quote 0
        • X
          xtingray @kshegunov last edited by xtingray

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


          Qt Developer

          kshegunov 1 Reply Last reply Reply Quote 0
          • kshegunov
            kshegunov Moderators @xtingray last edited by

            @xtingray
            Okay, this might work. But why are you using QPainterPath for the "logic" (assuming you have straight lines). You could keep a polygon, make the changes to it, and in the paint event use drawPolygon or convert it to a closed path and eventually draw it?

            Read and abide by the Qt Code of Conduct

            X 1 Reply Last reply Reply Quote 0
            • X
              xtingray @kshegunov last edited by

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


              Qt Developer

              kshegunov 1 Reply Last reply Reply Quote 0
              • kshegunov
                kshegunov Moderators @xtingray last edited by

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

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post