QPolygonF for non-intersecting subpaths
Solved
General and Desktop
-
Hi,
I am trying to make aQPolygonF
from two non-intersecting subpaths. I added two paths but when I usedunited
to group them they still connected.QPainterPath path1; qreal Width =100; qreal Height = 50; path1.moveTo(QPointF(X,Y)); path1.lineTo(QPointF(X + Width, Y )); path1.lineTo(QPointF(X + Width, Y + Height)); path1.lineTo(QPointF(X , Y + Height)); path1.closeSubpath(); QPainterPath path2; path2.moveTo(QPointF(X + 1.2*Width, Y + 1.2*Height)); path2.addRoundedRect(QRectF(X + 1.2*Width, Y + 1.2*Height,Width,Height),0.1*Width, 0.1*Height,Qt::AbsoluteSize); QPolygonF po1 = path1.toSubpathPolygons()[0]; QPolygonF po2 = path2.toSubpathPolygons()[0]; myPolygon = po2.united(po1);
this is what I get
As I understand
toSubpathPolygons()
and/orunited
should be used but I don't know how. Any idea, please. -
It seems that
united
(adding two separate paths) connects the path1' s end point with the starting point of path2... This is the line, you can see there.So I guess you cant use PainterPath to draw an item like this. Use a custom
QGraphicsItem
instead, where you add both rectangles or polygons to your painter and set a boundingRect that includes both of them.QRectF MyItem::boundingRect() const { return QRectF(-10, -10, 30, 30); } void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->drawRoundedRect(-10, -10, 20, 20, 5, 5); painter->drawRoundedRect(10, 10, 5, 5, 5, 5); }