PDA

View Full Version : How QGraphicsScene::setSceneRect exactly works?



rippa
10th September 2011, 22:43
Hello.

I have 3 examples:

1.

mgw = MyGW::_self(this);
ui->setupUi(this);
this->resize(300,300);
ui->verticalLayout->addWidget(mgw);

scene.setSceneRect(-700,-700,700,700);

mgw->setScene(&scene);
scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);

In this case graphicsView has long scrolls and my line starts not in top left corner of the view (as i expected) but somewhere around 80,200 point in graphicsView coordinates.

2.

mgw = MyGW::_self(this);
ui->setupUi(this);
this->resize(300,300);
ui->verticalLayout->addWidget(mgw);

scene.setSceneRect(-100,-100,100,100);

mgw->setScene(&scene);
scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);

No scrolls in this case and line is not visible

3.

mgw = MyGW::_self(this);
ui->setupUi(this);
this->resize(300,300);
ui->verticalLayout->addWidget(mgw);

// scene.setSceneRect(-100,-100,100,100);

mgw->setScene(&scene);
scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);

Line starts at top left corner but graphicsView has scrolls


So I need correct painting in external coordinates and no unnecessary scrolls. But most of all i want to understand how exactly should i use setSceneRect.

Thank you.

amleto
10th September 2011, 23:53
have you looked at the values returned by mapToScene in a debugger?