PDA

View Full Version : resizing the scene to the window



Urthas
12th November 2010, 08:23
Hello,

I have code that resizes the (currently empty) scene and view from within the window's resizeEvent(). To help me visualize the changes, I have included debug statements and a call to a helper function that draws a rectangle around the inside of the scene. Seems to work just fine, but I just wanted to make sure that I'm not making any faux pas, or that there isn't a better way to be doing it. Here's my code:



void MainWindow::resizeEvent(QResizeEvent *e)
{
QSize size(e->size());
int w = size.width()-2; // -2: 1 pixel from each side
int h = size.height()-2;
qDebug() << w+2 << "," << h+2;
scene->setSceneRect(0,0,w,h);
scene->updateBorder();
QMainWindow::resizeEvent(e);
}


And in the scene class:


void MyScene::updateBorder()
{
clear();
QRectF r = sceneRect();
addRect(r.x(), r.y(), r.width()-1, r.height()-1);
}


Thanks in advance for any suggestions.