c++ - Qt: resize a QGraphicsItem (boundingRect()) into a QGraphicsScene with the mouse -
i resize boundingrect()
of qgraphicsitem
using mouse.
to build found topic. managed make work right, bottomright , bottom of boundingrect()
following idea of topic.
but since position of item defined top left of boundingrect()
more complicated modify size of item moving edges linked position.
i tried top left bottom right moving. have bottom right fixed change size , not whole position.
here part of code:
void myclass::mousemoveevent(qgraphicsscenemouseevent *event) { if(_resizemode) //if bottom selected { preparegeometrychange(); _h = event->pos().y(); } if(_resizemode2) //if bottom right selected { preparegeometrychange(); _h = event->pos().y(); _w = event->pos().x(); } if(_resizemode3) //if right selected { preparegeometrychange(); _w = event->pos().x(); } if(_resizemode4) //if top left selected here issue { preparegeometrychange(); setpos(pos().x()+ event->pos().x(), pos().y() + event->pos().y()); _h = _h - event->pos().y(); _w = _w - event->pos().x(); } if(!_resizemode&&!_resizemode2&&!_resizemode3&&!_resizemode4) { update(); qgraphicsitem::mousemoveevent(event); } }
_h
, _w
or height , width implemented here:
qrectf aabb::boundingrect() const { return qrectf( 0, 0, _w, _h); }
does know how resize qgraphicsitem
selecting mouse each corners of boundingrect()
please?
the position of item defined top left of boundingrect()
in opinion, easiest way change position defined centre of item. in order this, define original bounding rect top left (-w/2, -h/2) , bottom right (w/2,h/2) or if you're returning in boundingrect function qrectf(-w/2, -h/2, w, h) (x,y,w,h).
then, create child 'tool' items @ corners, define area can click , drag corners of original item. may want these appear if item selected.
in moveevent of child item, update bounding rect of main item moves child. when mouse released, re-calculate boundingrect of main item, centre still @ (0,0).
this can done quite if map top left , bottom right of boundingrect , convert them scene-coordinates, using width , height, re-set item's local coordinates maintains (-w/2, -h/2, w, h);
Comments
Post a Comment