c++ - Relation between QTransform scale and boundingRect.size() -
i have little concern relation between qtransform scale , width , height return values in boundingrect() method of qgraphicsitem. want scale qgraphicsitem boundingrect size. i.e. if size of item 100,100 passing in boundingrect() method after increasing size of item mousemove event. if increased width , height 400,300 respectively scale factors 4,3? appreciable.
this code
this->setpos(minmax().first.x(), minmax().first.y()); qreal w = minmax().second.x() - minmax().first.x(); qreal h = minmax().second.y() - minmax().first.y(); qreal scalefactorw = w / boundingrect().width(); qreal scalefactorh = h / boundingrect().height(); qtransform trans; trans.scale(scalefactorw, scalefactorh); settransform(trans); bottompoints = qpointf(w, h);
minmax function is:
float xmin = 0, xmax = 0, ymin = 0, ymax = 0; qlist<double> xvalues, yvalues; xvalues << shaper[0]->scenepos().x() << shaper[1]->scenepos().x() << shaper[2]->scenepos().x() << shaper[3]->scenepos().x() << shaper[4]->scenepos().x() << shaper[5]->scenepos().x() << shaper[6]->scenepos().x() << shaper[7]->scenepos().x(); yvalues << shaper[0]->scenepos().y() << shaper[1]->scenepos().y() << shaper[2]->scenepos().y() << shaper[3]->scenepos().y() << shaper[4]->scenepos().y() << shaper[5]->scenepos().y() << shaper[6]->scenepos().y() << shaper[7]->scenepos().y(); qsort(xvalues.begin(), xvalues.end()); qsort(yvalues.begin(), yvalues.end()); xmin = xvalues.first(); xmax = xvalues.last(); ymin = yvalues.first(); ymax = yvalues.last(); return qmakepair(qpointf(xmin, ymin), qpointf(xmax, ymax));
shaper qgraphicsitem resizing item.
thanks :)
thanks showing code.
as said before,
trans.scale(scalefactorw, scalefactorh);
won't change size returned qgraphicsitem::boundingrect
.
but in fact, qgraphicsitem::setscale
has same behaviour , boundingrect()
item doesn't change either.
qtransform::scale , qgraphicsitem::setscale not same, both useful change image size. well, in case of qtransform, you're scaling coordinate system.
i think example best way of explaining myself.
(this
inherits qgraphicsitem
)
qwarning() << "qgraphicsitem::scale(): " << this->scale(); qrectf br = this->boundingrect(); qwarning() << "qgraphicsitem::boundingrect() size / x / y / w / h: " << br.size() << " / " << br.x() << " / " << br.y() << " / " << br.width() << " / " << br.height(); qtransform trans = this->transform(); trans.scale(2.0, 2.0); this->settransform(trans); /* comment trans.scale(2.0, 2.0) , uncomment following line check difference using logs. */ // this->setscale(2.0); qwarning() << "qgraphicsitem::scale(): " << this->scale(); br = this->boundingrect(); qwarning() << "qgraphicsitem::boundingrect() size / x / y / w / h: " << br.size() << " / " << br.x() << " / " << br.y() << " / " << br.width() << " / " << br.height(); qwarning() << "boundingrect * item_scale: " << this->boundingrect().size() * this->scale();
Comments
Post a Comment