DrawableRectangle with dashed stroke

Is this even possible? I have not been able to figure it out…

I want to draw a marquee with the mouse around portions of my component. I have made it work with a DrawableRectangle, but I would like the stroke to be dashed and it seems this may be impossible.

auto area = getLocalBounds().toFloat().reduced (0.5f);
float cornerSize = 2.f;
float dashLengths[2] = { 4.f, 2.f };
Path path;
path.addRoundedRectangle (area, cornerSize);
PathStrokeType strokeType (0.5f);
strokeType.createDashedStroke (path, path, dashLengths, numElementsInArray (dashLengths));
g.setColour (Colours::red);
g.strokePath (path, strokeType);

Thank you - I was able to get your example working, by storing the marquee Rectangle being drawn with the mouse in mouseDrag() ,and continually calling repaint(), and then putting the above code inside my component’s paint() method.