qt - Customizing shape of bounding rect -
i drawing line using mouse clicks. line drawn using paint function as:
painter->drawline(start_p, end_p);
the bounding rect of line defined as:
qrectf line::boundingrect() const { // bounding rectangle line homecoming qrectf(start_p, end_p).normalized(); }
this shows line painted. bounding rect shown:
i want have bounding rect according shape of item, like:
how accomplish this?
edit
while selecting of overlapping lines, 1 bounding rect on top selected(see figure below). making utilize of setzvalue
won't work here. want implement minimizing bounding rect shape of line.
if have item not shaped rectangle, or rotated rectangle utilize qgraphicsitem::shape
.
this function should homecoming qpainterpath
. should able create path using qpainterpath::addpolygon
.
here little example:
qpainterpath item::shape() const { qpainterpath path; qpolygon polygon; polygon << qpoint(0, 0); polygon << qpoint(5, 5); polygon << qpoint(width, height); polygon << qpoint(width - 5, height - 5); path.addpolygon(polygon); homecoming path; }
you of course of study should calculate points within path in different way, point. when click on item, select if click happened within shape defined qpainterpath
.
if ever need create curvy lines, can utilize qpainterpathstroker::createstroke
suggested cmannett85.
qt bounding-box qgraphicsitem
No comments:
Post a Comment