Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    3
    1077
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      DoHuuVi last edited by

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

      int main(int argc, char *argv[]) {
      QApplication a(argc, argv);
      QGraphicsScene scene;
      QGraphicsView view(&scene);
      view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      view.setFixedSize(800, 600);
      view.show();
      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.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • D
          DoHuuVi last edited by

          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.
          Thanks

          1 Reply Last reply Reply Quote 0
          • First post
            Last post