I am drawing a line using mouse clicks. The line is drawn using paint function as:
painter->drawLine(start_p, end_p);
The bounding rect of line is defined as:
QRectF Line::boundingRect() const
{
// bounding rectangle for line
return QRectF(start_p, end_p).normalized();
}
This shows the line painted. I get the bounding rect for this as shown:
I want to have the bounding rect according to the shape of the item, something like:
How to achieve this?
Edit
While selecting any of the overlapping lines, the one with bounding rect on top is selected(see figure below). Even making use of setZValue
won't work here.
I want to implement this by minimizing the bounding rect to the shape of line.
QGraphicsItem::shape
. – KauslickQPainterPath
. You might be able to create your shape withQPainterPath::addPolygon
. – KauslickQPainterPathStroker::createStroke(..)
if the user ever wants to create curvy lines. – Desdemona