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:
{
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();
}
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);
}
To copy to clipboard, switch view to plain text mode
And in the scene class:
void MyScene::updateBorder()
{
clear();
addRect(r.x(), r.y(), r.width()-1, r.height()-1);
}
void MyScene::updateBorder()
{
clear();
QRectF r = sceneRect();
addRect(r.x(), r.y(), r.width()-1, r.height()-1);
}
To copy to clipboard, switch view to plain text mode
Thanks in advance for any suggestions.
Bookmarks