QPainterPath: strokeStart, strokeEnd



  • I have a QPainterPath composed with arcTo, cubicTo, etc and maybe closed, maybe not. I want to stroke a section say from strokeStart at 0.2 to strokeEnd at 0.7. Can I do this?



  • Something like the following is probably my best option:

    auto start = 0.2f;
    auto end = 0.8f;
    auto resolution = 10;
    auto step = (end - start) / resolution;
    auto width = 8;
            
    QPainterPath masterPath = QPainterPath();
    masterPath.lineTo(boundingRect().size().width(), boundingRect().size().height());
    painter->strokePath(masterPath, QPen(Qt::black, width));
        
    QPainterPath shapePath = QPainterPath();
    shapePath.moveTo(masterPath.pointAtPercent(start));
            
    for (auto i = 0; i < resolution; i ++)
    {
         start += step;
         shapePath.lineTo(masterPath.pointAtPercent(start));
    }
    painter->strokePath(shapePath, QPen(Qt::cyan, width));
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.