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:
//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);
//Scene
pScene = new QGraphicsScene(ui->view);
pScene->setSceneRect(0, 0, ui->view->width(), ui->view->height());
//View
ui->view->setInteractive(false);
ui->view->setScene(pScene);
QGraphicsTextItem* txtG = pScene->addText("G");
txtG->setPos(0, 0);
QGraphicsTextItem* txtD = pScene->addText("D");
txtD->setPos(110, 110);
To copy to clipboard, switch view to plain text mode
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!
Bookmarks