Fixed QGraphicsScene in view
Hi,
by default, when we add an item in a QGraphicsScene the view tries to center it. If we add one more it tries to center both... I'd like to have it "static", a viewport unable to move.
In order to do that I set the size of the scene to the view:
Code:
//Scene
pScene->setSceneRect(0, 0, ui->view->width(), ui->view->height());
//View
ui->view->setInteractive(false);
ui->view->setScene(pScene);
txtG->setPos(0, 0);
txtD->setPos(110, 110);
It solves the problem, but the coordinates seem to be wrong, 0, 0 should be corner top-left and it's close to the view's center.
Does anybody know how I can solve this problem or any other way to "fix the viewport"?
thanks!
Re: Fixed QGraphicsScene in view
If I were you, I'd check if ui->view->width() and ui->view->height() return values you expect since if you call this code before the window is first shown, they are likely to have bogus values (as of course explained in the docs).