Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the real effect of function: QGraphicsScene::setSceneRect?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • 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 Offline
    D Offline
    DoHuuVi
    wrote on last edited by
    #1

    #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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        DoHuuVi
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved