0

Ok, I basically have randomly placed graphics items on a graphics scene. I open a window and display these items. When I resize the window, I want this items to stay the same size but reposition proportionally to the window size. How I did this was I subclassed the graphics view and then when there was a resize event, it sent the resize object to my graphicsscene object. I was then able to do something like this:

double scaleX = double(event->size().width())/double(event->oldSize().width());
double scaleY = double(event->size().height())/double(event->oldSize().height());

Then I used these values to do this:

derivedPointItem->setPos( derivedPointItem->pos().x() * scaleX,
                          derivedPointItem->pos().y() * scaleY );

This works ok, but it's not quite right if I resize the window really small or large. I think the problem is that the graphicsscene rect and the graphics view rect are not the same or something. Furthermore, I have a background which resizes to 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 is something I need in the program I'm writing. Also, it allows me to see if the resizing works. I basically can set the background to be a polygon, then place points on the edges of the polygon. When I resize the image to be very large or small the points are no longer on the vertices of the polygon althought they are somewhat close. Anyone know a better way to do this or a way to fix it? Thanks.

EDIT: Here's the project I'm working on:

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

p.i.g.
  • 2,815
  • 2
  • 24
  • 41
JustinBlaber
  • 4,629
  • 2
  • 36
  • 57
  • Here's the project I'm working on: "https://www.dropbox.com/s/myxi8kvdl7x9ye2/ncorr.tar.gz" Also, what I meant to say is to relocate their position proportionally to the window size. But, the size of the items themselves will stay the same. Hopefully this clears things up. Thanks. Also, to use the program just do file>upload reference and then click "set roi." Resize the window and you'll see what I mean. – JustinBlaber Jun 07 '12 at 17:53
  • One more thing. I'm basically just trying to recreate impoly from matlab. Also, I've been making this on ubuntu, hopefully it works on whatever system you're using... Crap, one more thing. To close to roi just right click. – JustinBlaber Jun 07 '12 at 17:58

1 Answers1

1

This method actually works (although I'm not sure if it's the best method to use...). Anyway, it ended up being a coding error due to the setPos() function. The setPos() function in my program worked by specifying the coordinates of the top left corner of the image rather than the center. This ended up causing some errors.

JustinBlaber
  • 4,629
  • 2
  • 36
  • 57