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. QPolygonF for non-intersecting subpaths
QtWS25 Last Chance

QPolygonF for non-intersecting subpaths

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterpathqpolygonfqt5
5 Posts 2 Posters 907 Views
  • 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.
  • S Offline
    S Offline
    sDmt
    wrote on 3 Mar 2020, 16:05 last edited by
    #1

    Hi,
    I am trying to make a QPolygonF from two non-intersecting subpaths. I added two paths but when I used united to group them they still connected.

    QPainterPath path1;
            qreal Width =100;
            qreal Height = 50;
            path1.moveTo(QPointF(X,Y));
            path1.lineTo(QPointF(X + Width, Y ));
            path1.lineTo(QPointF(X + Width, Y + Height));
            path1.lineTo(QPointF(X , Y + Height));
            path1.closeSubpath();
    
            QPainterPath path2;
            path2.moveTo(QPointF(X + 1.2*Width, Y + 1.2*Height));
            path2.addRoundedRect(QRectF(X + 1.2*Width, Y + 1.2*Height,Width,Height),0.1*Width, 0.1*Height,Qt::AbsoluteSize);
    
            QPolygonF po1 = path1.toSubpathPolygons()[0];
            QPolygonF po2 = path2.toSubpathPolygons()[0];
    
            myPolygon = po2.united(po1);
    

    this is what I get
    Capture.JPG

    As I understand toSubpathPolygons() and/or united should be used but I don't know how. Any idea, please.

    P 1 Reply Last reply 3 Mar 2020, 18:13
    0
    • S sDmt
      3 Mar 2020, 16:05

      Hi,
      I am trying to make a QPolygonF from two non-intersecting subpaths. I added two paths but when I used united to group them they still connected.

      QPainterPath path1;
              qreal Width =100;
              qreal Height = 50;
              path1.moveTo(QPointF(X,Y));
              path1.lineTo(QPointF(X + Width, Y ));
              path1.lineTo(QPointF(X + Width, Y + Height));
              path1.lineTo(QPointF(X , Y + Height));
              path1.closeSubpath();
      
              QPainterPath path2;
              path2.moveTo(QPointF(X + 1.2*Width, Y + 1.2*Height));
              path2.addRoundedRect(QRectF(X + 1.2*Width, Y + 1.2*Height,Width,Height),0.1*Width, 0.1*Height,Qt::AbsoluteSize);
      
              QPolygonF po1 = path1.toSubpathPolygons()[0];
              QPolygonF po2 = path2.toSubpathPolygons()[0];
      
              myPolygon = po2.united(po1);
      

      this is what I get
      Capture.JPG

      As I understand toSubpathPolygons() and/or united should be used but I don't know how. Any idea, please.

      P Offline
      P Offline
      Pl45m4
      wrote on 3 Mar 2020, 18:13 last edited by
      #2

      @sDmt

      What kind of polygon do you expect? How it should look like?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply 3 Mar 2020, 18:27
      0
      • P Pl45m4
        3 Mar 2020, 18:13

        @sDmt

        What kind of polygon do you expect? How it should look like?

        S Offline
        S Offline
        sDmt
        wrote on 3 Mar 2020, 18:27 last edited by
        #3

        @Pl45m4 thanks for the reply.
        I just need to get rid of the line connecting the two shapes. Also, I want to handle them as group such that when I drag one the other is dragged as well ans so on.

        P 1 Reply Last reply 4 Mar 2020, 16:06
        0
        • S sDmt
          3 Mar 2020, 18:27

          @Pl45m4 thanks for the reply.
          I just need to get rid of the line connecting the two shapes. Also, I want to handle them as group such that when I drag one the other is dragged as well ans so on.

          P Offline
          P Offline
          Pl45m4
          wrote on 4 Mar 2020, 16:06 last edited by Pl45m4 3 Apr 2020, 16:50
          #4

          @sDmt

          It seems that united (adding two separate paths) connects the path1' s end point with the starting point of path2... This is the line, you can see there.

          So I guess you cant use PainterPath to draw an item like this. Use a custom QGraphicsItem instead, where you add both rectangles or polygons to your painter and set a boundingRect that includes both of them.

          QRectF MyItem::boundingRect() const
          {
              return QRectF(-10, -10, 30, 30);
          }
          
          
          void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
          {
                  painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
                  painter->drawRoundedRect(10, 10, 5, 5, 5, 5);
          }
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          S 1 Reply Last reply 4 Mar 2020, 17:23
          3
          • P Pl45m4
            4 Mar 2020, 16:06

            @sDmt

            It seems that united (adding two separate paths) connects the path1' s end point with the starting point of path2... This is the line, you can see there.

            So I guess you cant use PainterPath to draw an item like this. Use a custom QGraphicsItem instead, where you add both rectangles or polygons to your painter and set a boundingRect that includes both of them.

            QRectF MyItem::boundingRect() const
            {
                return QRectF(-10, -10, 30, 30);
            }
            
            
            void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
            {
                    painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
                    painter->drawRoundedRect(10, 10, 5, 5, 5, 5);
            }
            
            S Offline
            S Offline
            sDmt
            wrote on 4 Mar 2020, 17:23 last edited by
            #5

            @Pl45m4 True, I see that QPainterPath is getting me nowhere in this case. Thanks.

            1 Reply Last reply
            0

            1/5

            3 Mar 2020, 16:05

            • Login

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