c++qtqpainterpath

Changing Color of subpaths within a QGraphicsPathItem?


So I'm currently using the code here, previous post to create and update a QGraphicsPathItem.

All of this works fine, but now I need to change the color of the subpaths included in the pathItem. I can see that using QPainter, I could stroke the Path as found in other examples here, but I'm not using QPainter as this is within a GraphicsScene.

I understand that:

path.moveTo(newPoint);

creates the new subpath, closing the old one, but how do I change the QPen or just the color applied to this subpath?

So far I can only see how to change the Pen applied to the entire QGraphicsPathItem which is not what I need.

My thought is I will need to create a new QGraphicsPathItem every time the color needs to be altered. I sure hope not.

Thanks for your help in advance.


Solution

  • The short answer is that I cannot apply a separate Pen to subpaths of a QGraphicsPathItem. In order to create the effect desired, I need to create multiple QGraphicsPathItems, which is what I hoped wouldn't be the case.