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. Can't move QGraphicsEllipseItem
Forum Updated to NodeBB v4.3 + New Features

Can't move QGraphicsEllipseItem

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 783 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.
  • cpperC Offline
    cpperC Offline
    cpper
    wrote on last edited by
    #1

    Hi, I'm trying to draw a circle, and the move it 150 pixels on the X axis. Here is the simplified code:

    QGraphicsScene scene;
    QGraphicsEllipseItem circle;
    
    scene.addItem(&circle);
    circle.setRect(150,-0,200,200);    
    circle.setPos(150,0);
    circle.moveBy(150,0);
    circle.setX(150);
    

    The value 150 in the four lines do nothing. What's the correct way to move the item ?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      circle.moveBy(150,0);

      This moves your circle so x == 300.

      circle.setX(150);

      This moves it back to x == 150.

      So it all works correctly (unless I misunderstood you).

      (Z(:^

      cpperC 1 Reply Last reply
      0
      • sierdzioS sierdzio

        circle.moveBy(150,0);

        This moves your circle so x == 300.

        circle.setX(150);

        This moves it back to x == 150.

        So it all works correctly (unless I misunderstood you).

        cpperC Offline
        cpperC Offline
        cpper
        wrote on last edited by
        #3

        @sierdzio The last four lines are my attempts to move the circle, but none work. The circle is still in the center of the scene.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          All look correct. Can you show relevant parts of your real code? Perhaps there is something wrong there.

          (Z(:^

          cpperC 1 Reply Last reply
          0
          • sierdzioS sierdzio

            All look correct. Can you show relevant parts of your real code? Perhaps there is something wrong there.

            cpperC Offline
            cpperC Offline
            cpper
            wrote on last edited by
            #5

            @sierdzio I just found out the problem. I was only experimenting with a single circle, and it seems that after the translation, the whole scene is moved so that its contents are centered.
            When adding a second circle at 0,0 I now can notice the first one is indeed translated. The center of the scene is now the point between the circles.
            Is there a way to fix the scene, so that it stops centering its contents ?

            Pl45m4P 1 Reply Last reply
            0
            • cpperC cpper

              @sierdzio I just found out the problem. I was only experimenting with a single circle, and it seems that after the translation, the whole scene is moved so that its contents are centered.
              When adding a second circle at 0,0 I now can notice the first one is indeed translated. The center of the scene is now the point between the circles.
              Is there a way to fix the scene, so that it stops centering its contents ?

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @cpper

              Set a static sceneRect to your QGraphicsScene.

              graphicsView->scene()->setSceneRect(0, 0, graphicsView->width(), graphicsView->height());
              

              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
              1
              • cpperC Offline
                cpperC Offline
                cpper
                wrote on last edited by
                #7

                @Pl45m4 said in Can't move QGraphicsEllipseItem:

                graphicsView->scene()->setSceneRect(0, 0, graphicsView->width(), graphicsView->height());

                Thanks guys. That works fine.

                1 Reply Last reply
                1

                • Login

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