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. QGraphicscene changes size
Forum Updated to NodeBB v4.3 + New Features

QGraphicscene changes size

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 798 Views 2 Watching
  • 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.
  • V Offline
    V Offline
    Vera
    wrote on last edited by
    #1

    Hello all,

    I encountered a problem with QGraphicsscene. I am making a simple pong game and using a graphicsscene where I put my items in. But when I want to reset the game and put all the items back in their original position the graphicsscine seems like it had gotten twice(or more) bigger. Is there a way to keep the scene always at the same size, I couldn't find anything about this on the internet.
    Thanks!

    raven-worxR 1 Reply Last reply
    0
    • V Vera

      Hello all,

      I encountered a problem with QGraphicsscene. I am making a simple pong game and using a graphicsscene where I put my items in. But when I want to reset the game and put all the items back in their original position the graphicsscine seems like it had gotten twice(or more) bigger. Is there a way to keep the scene always at the same size, I couldn't find anything about this on the internet.
      Thanks!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Vera
      QGraphicsView::setScreneRect()
      QGraphicsScene::setSceneRect()

      If one those are not set the default value is the bounding rect of all child items.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • V Offline
        V Offline
        Vera
        wrote on last edited by
        #3

        Thanks for your reply.
        And sorry for the late response.
        I set them both but that didn't seem to help, but I found out after a long search that the objects i put inside the scene get their own coordinate system. When I put an object in at 400, 300 it is there but when it has moved and I want it back at its original place I have to set it position to 0,0 to reset it. This is really annoying as I cant use the dimension of the scene to check if the ball in the game has a collision with the top wall.
        Is there a way to have the objects always use the coordinate system from the scene?

        mrjjM 1 Reply Last reply
        0
        • V Vera

          Thanks for your reply.
          And sorry for the late response.
          I set them both but that didn't seem to help, but I found out after a long search that the objects i put inside the scene get their own coordinate system. When I put an object in at 400, 300 it is there but when it has moved and I want it back at its original place I have to set it position to 0,0 to reset it. This is really annoying as I cant use the dimension of the scene to check if the ball in the game has a collision with the top wall.
          Is there a way to have the objects always use the coordinate system from the scene?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Vera
          Hi
          there are function to map from items coordinates to global and reverse
          QPointF QGraphicsItem::mapToScene(const QPointF &point)
          That should report 400x300 for that item.

          Did you read
          http://doc.qt.io/qt-5/graphicsview.html
          The Graphics View Coordinate System ?

          V 1 Reply Last reply
          1
          • mrjjM mrjj

            @Vera
            Hi
            there are function to map from items coordinates to global and reverse
            QPointF QGraphicsItem::mapToScene(const QPointF &point)
            That should report 400x300 for that item.

            Did you read
            http://doc.qt.io/qt-5/graphicsview.html
            The Graphics View Coordinate System ?

            V Offline
            V Offline
            Vera
            wrote on last edited by
            #5

            @mrjj
            Thanks for the answer. This worked! Thank you!

            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