Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainterPath closed shape is possible?
Forum Updated to NodeBB v4.3 + New Features

QPainterPath closed shape is possible?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.2k Views 1 Watching
  • 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 Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    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

    kshegunovK 1 Reply Last reply
    0
    • X xtingray

      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!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

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

      Read and abide by the Qt Code of Conduct

      X 1 Reply Last reply
      0
      • kshegunovK kshegunov

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

        X Offline
        X Offline
        xtingray
        wrote on last edited by xtingray
        #3

        @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

        kshegunovK 1 Reply Last reply
        0
        • X 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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @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
          0
          • kshegunovK kshegunov

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

            X Offline
            X Offline
            xtingray
            wrote on last edited by
            #5

            @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

            kshegunovK 1 Reply Last reply
            0
            • X xtingray

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

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

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

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved