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 14.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.
  • C Offline
    C Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on 28 Dec 2015, 15:49 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();
    
    J 1 Reply Last reply 28 Dec 2015, 16:27
    2
    • C Chris Kawa
      28 Dec 2015, 15:49

      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();
      
      J Offline
      J Offline
      Joel Bodenmann
      wrote on 28 Dec 2015, 16:27 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
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 28 Dec 2015, 16:28 last edited by
        #23

        well what can we say ?
        Chris rules :)

        J 1 Reply Last reply 28 Dec 2015, 16:30
        1
        • M mrjj
          28 Dec 2015, 16:28

          well what can we say ?
          Chris rules :)

          J Offline
          J Offline
          Joel Bodenmann
          wrote on 28 Dec 2015, 16:30 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

          21/24

          28 Dec 2015, 15:49

          • Login

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