c++ - Reposition graphics items on window resize -


ok, have randomly placed graphics items on graphics scene. open window , display these items. when resize window, want items stay same size reposition proportionally window size. how did subclassed graphics view , when there resize event, sent resize object graphicsscene object. able this:

double scalex = double(event->size().width())/double(event->oldsize().width()); double scaley = double(event->size().height())/double(event->oldsize().height()); 

then used these values this:

derivedpointitem->setpos( derivedpointitem->pos().x() * scalex,                           derivedpointitem->pos().y() * scaley ); 

this works ok, it's not quite right if resize window small or large. think problem graphicsscene rect , graphics view rect not same or something. furthermore, have background resizes window size:

void roiwindow::drawbackground( qpainter* painter, const qrectf& rect ) {     this->setscenerect(0,0,rect.width(),rect.height());     painter->save();     painter->drawimage(rect, *refimage);     painter->restore(); } 

this need in program i'm writing. also, allows me see if resizing works. can set background polygon, place points on edges of polygon. when resize image large or small points no longer on vertices of polygon althought close. know better way or way fix it? thanks.

edit: here's project i'm working on:

dropbox.com/s/myxi8kvdl7x9ye2/ncorr.tar.gz

this method works (although i'm not sure if it's best method use...). anyway, ended being coding error due setpos() function. setpos() function in program worked specifying coordinates of top left corner of image rather center. ended causing errors.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -