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. Generate an outline from a set of rectangles
Forum Updated to NodeBB v4.3 + New Features

Generate an outline from a set of rectangles

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 455 Views 2 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.
  • rkhaotixR Offline
    rkhaotixR Offline
    rkhaotix
    wrote on last edited by
    #1

    Hey everyone!

    I'm trying to create an outline path from a set of rectangles using QPainterPath and QPainterPathStroke but I'm not getting the desired result.

    Basically, I'm creating a path by adding rectangles to it by using addRect(), after that, I draw the generated path in my QGraphicsScene. What I need is something like the image below:

    path_outline.png

    As you can see, I need a path that is composed of the extreme points of the rectangles or by joining their bounding rectangles in such a way to produce a polygon that can serve as an outline item without having lines crossing over the rectangles. Unfortunately, the result I'm getting is:

    path_outline1.png

    I'm pretty sure that I'm missing something. So, Is there something that can help me to produce that outline? Any tips? Examples?

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      I am pretty sure it won't do what you want but what do you get if you make different path for each rectangle and use QPainterPath::connectPath ?

      Otherwise, you would have to store your rectangle and then add the three points of each that would generate the outline you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      rkhaotixR 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I am pretty sure it won't do what you want but what do you get if you make different path for each rectangle and use QPainterPath::connectPath ?

        Otherwise, you would have to store your rectangle and then add the three points of each that would generate the outline you want.

        rkhaotixR Offline
        rkhaotixR Offline
        rkhaotix
        wrote on last edited by
        #3

        @SGaist Hi! thanks for your reply.

        what do you get if you make different path for each rectangle and use QPainterPath

        I don't get it... could you elaborate, please?

        Otherwise, you would have to store your rectangle and then add the three points of each that would generate the outline you want.

        I've already tried the three points approach, but it didn't work well. Since the arrangement of the rectangles can be changed by the user it's quite complicated to determine which points to use as a reference to create the path.

        Anyway, I'll keep trying to create a solution for this problem.

        Thanks once again!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry, my link text was broken. It's fixed now. The word missing was connectPath.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            create points and draw them as polylines. N is the number. The first and the last points are the same.

            QPainter painter( this );
            painter.setRenderHint( QPainter::Antialiasing, true );
            painter.setPen( m_pen );
            painter.setBrush( m_brush );
            painter.save();
            
            painter.drawPolyline( m_polylinePoints, N );
            
            painter.restore();
            

            First order your rectangles from top to bottom and left to right by comparing the left top corner coordinates.

            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