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 from list of points
Forum Updated to NodeBB v4.3 + New Features

QPainterPath from list of points

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterpathqgraphicsitemshape
24 Posts 4 Posters 13.2k Views 3 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by Chris Kawa
    #21

    As mentioned above you can use QPainterPathStroker. The problem is it will create tiny loops on the inside of the joints, so you need to simplify the path afterwards.
    Sample code:

    QVector<QPoint> points { QPoint(30,30), QPoint(100, 100), QPoint(200,50) };
    
    QPainterPath basePath;
    basePath.addPolygon(QPolygon(points));
    
    QPainterPathStroker str;
    str.setCapStyle(Qt::RoundCap);
    str.setWidth(10.0);
    
    QPainterPath resultPath = str.createStroke(basePath).simplified();
    
    Joel BodenmannJ 1 Reply Last reply
    2
    • Chris KawaC Chris Kawa

      As mentioned above you can use QPainterPathStroker. The problem is it will create tiny loops on the inside of the joints, so you need to simplify the path afterwards.
      Sample code:

      QVector<QPoint> points { QPoint(30,30), QPoint(100, 100), QPoint(200,50) };
      
      QPainterPath basePath;
      basePath.addPolygon(QPolygon(points));
      
      QPainterPathStroker str;
      str.setCapStyle(Qt::RoundCap);
      str.setWidth(10.0);
      
      QPainterPath resultPath = str.createStroke(basePath).simplified();
      
      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by
      #22

      Wow, I am deeply impressed. Using the code shown by @Chris-Kawa gave exactly the desired result:
      Alt text

      Thank you very much for your help, guys. Very appreciated!

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #23

        well what can we say ?
        Chris rules :)

        Joel BodenmannJ 1 Reply Last reply
        1
        • mrjjM mrjj

          well what can we say ?
          Chris rules :)

          Joel BodenmannJ Offline
          Joel BodenmannJ Offline
          Joel Bodenmann
          wrote on last edited by
          #24

          @mrjj Well, thanks to you and @kshegunov too. You guys are amazing!

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          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