What is the real effect of function: QGraphicsScene::setSceneRect?

  • #include <QApplication>
    #include <QGraphicsScene>
    #include <QGraphicsView>

    int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    QGraphicsScene scene;
    QGraphicsView view(&scene);
    view.setFixedSize(800, 600);
    scene.setSceneRect(100, 100, 300, 300);
    // scene.setSceneRect(0, 0, 300, 300);
    //scene.setSceneRect(-100, -100, 300, 300);
    scene.addRect(0, 0, 300, 300, QPen(Qt::blue));
    scene.addRect(0, 0, 1, 1, QPen(Qt::red));
    return a.exec();

    Changing the arguments of setSceneRect, I see the red point and the blue rectangle is positioned on different points in the window, why? Can you help me? I read the Qt documents about "Graphics View Framework" and QGraphicsScene, QGraphicsView, QGraphicsItem, Coordinates, ... but I cannot imagine why changing the positions make those items changing the positions in the window/view.

  • Lifetime Qt Champion


    From the doc, I'd say that the items are still put at the same global places but your scene is looking at a different place in the global scene.

  • I think I've understood the issue. The center of the view will be the same as the center of the scene's rect at begin.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.