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. Graphics view scene resize and origin point

Graphics view scene resize and origin point

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 664 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.
  • M Offline
    M Offline
    Mario1159
    wrote on 22 Jul 2019, 23:02 last edited by
    #1

    In my graphics view i have a line from the point (0,0) to the point (100,100) but i was expecting that the line would go from the top left corner of my graphics view to somewhere to the right bottom but instead it shows up like the view had some margins and when i resize the items don't change their size and position, so how i can make them resize and reposition according to the window and how i make the top left corner of my graphics view have the coordinates 0,0?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jul 2019, 20:04 last edited by
      #2

      Hi,

      The graphics view coordinate system is explained here.

      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
      1
      • M Offline
        M Offline
        Mario1159
        wrote on 31 Jul 2019, 00:15 last edited by
        #3

        Now it became more clear but i still have one problem, i think the rect of my graphics view isn't accurate in the dialog constructor.
        I have this function that gets called in my dialog constructor and in the resizeEvent:

        void GameEditor::resizeGraphicsViewScene() {
        QRect crect = ui.graphicsView->contentsRect();
        ui.graphicsView->setSceneRect(0, 0, crect.width(), crect.height());
        QRectF r = ui.graphicsView->sceneRect();
        qDebug() << r;
        line->setLine(QLineF(0, 0, r.width(), r.height()));
        }

        When i run my application i don't get exactly my expected behavior which is the line going from the origin point to the bottom right corner of the graphics view widget.

        And when i maximize my window my resize function it works perfect

        And when i go back to the previous "resolution" it still works fine

        So why the graphics view content rect have some weird values in the start of my application?

        J P 2 Replies Last reply 31 Jul 2019, 05:23
        0
        • M Mario1159
          31 Jul 2019, 00:15

          Now it became more clear but i still have one problem, i think the rect of my graphics view isn't accurate in the dialog constructor.
          I have this function that gets called in my dialog constructor and in the resizeEvent:

          void GameEditor::resizeGraphicsViewScene() {
          QRect crect = ui.graphicsView->contentsRect();
          ui.graphicsView->setSceneRect(0, 0, crect.width(), crect.height());
          QRectF r = ui.graphicsView->sceneRect();
          qDebug() << r;
          line->setLine(QLineF(0, 0, r.width(), r.height()));
          }

          When i run my application i don't get exactly my expected behavior which is the line going from the origin point to the bottom right corner of the graphics view widget.

          And when i maximize my window my resize function it works perfect

          And when i go back to the previous "resolution" it still works fine

          So why the graphics view content rect have some weird values in the start of my application?

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 31 Jul 2019, 05:23 last edited by
          #4

          @mario1159 said in Graphics view scene resize and origin point:

          So why the graphics view content rect have some weird values in the start of my application?

          I think because you're doing this in the constructor. In the constructor the object is being constructed, so you can't trust that contentsRect() will return anything meaningful.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • M Mario1159
            31 Jul 2019, 00:15

            Now it became more clear but i still have one problem, i think the rect of my graphics view isn't accurate in the dialog constructor.
            I have this function that gets called in my dialog constructor and in the resizeEvent:

            void GameEditor::resizeGraphicsViewScene() {
            QRect crect = ui.graphicsView->contentsRect();
            ui.graphicsView->setSceneRect(0, 0, crect.width(), crect.height());
            QRectF r = ui.graphicsView->sceneRect();
            qDebug() << r;
            line->setLine(QLineF(0, 0, r.width(), r.height()));
            }

            When i run my application i don't get exactly my expected behavior which is the line going from the origin point to the bottom right corner of the graphics view widget.

            And when i maximize my window my resize function it works perfect

            And when i go back to the previous "resolution" it still works fine

            So why the graphics view content rect have some weird values in the start of my application?

            P Offline
            P Offline
            Pl45m4
            wrote on 31 Jul 2019, 07:55 last edited by Pl45m4
            #5

            @mario1159

            Try to set up your GraphicsView inside the showEvent of your Widget / window.
            It worked for me some time ago (I tried to set a centered label over the GraphicsView, but 50% of height was always returning wrong values until I used the showEvent)
            As @jsulm already wrote, some values of your GraphicsView may be uninitialized / not set correcty while constructing

            QRectF r = ui.graphicsView->sceneRect(); // This rect could be wrong rect...
            qDebug() << r;
            line->setLine(QLineF(0, 0, r.width(), r.height())); // ...so this wont work as expected
            

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • M Offline
              M Offline
              Mario1159
              wrote on 31 Jul 2019, 21:44 last edited by
              #6

              Thanks that worked

              1 Reply Last reply
              0

              3/6

              31 Jul 2019, 00:15

              • Login

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