Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Solved Focusing on item

    Game Development
    qgraphicsitem qgraphicsscene qabstractproxym
    2
    5
    1604
    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.
    • W
      Walux last edited by

      Hi ,
      I want my (custom) QGraphicsItem to always be centered in the screen while all other items stand still in the scene .

      Nice regards :)

      Taking things from beginning to end : That's my entertainment !

      1 Reply Last reply Reply Quote 0
      • W
        Walux last edited by

        I tried ensureVisible() and centerOn() but unfortunately that didn't work , even tho i only have one instance of the item in the scene .
        Does anyone have any idea what to do ?

        I'll be grateful for your support :)

        Taking things from beginning to end : That's my entertainment !

        Joel Bodenmann 1 Reply Last reply Reply Quote 0
        • Joel Bodenmann
          Joel Bodenmann @Walux last edited by

          This is not how the Qt Graphics Framework works (note the link, I'd strongly suggest giving it a read before starting to work with it).
          You can't fix an item in the scene and let all the others move around. What you would do is having all the other items fixed and move that one item around.

          Keeping it centered on the scene is also not possible. all you can do is keeping it centered on the view. For stuff like QGraphicsView::centerOn() to work the viewport must actually be able to scroll. This means that if your scene is too small / your view to large (ignoring the scaling here) it won't move at all. You might want to play around in the 40000 Chips example to get a feeling what it means when the scene is moving and when the viewport is just too large to do any panning at all.
          I assume that this explanation didn't help at all but increased confusion instead. It should be a lot clearer to you once you read the linked documentation and played around with some of the examples.

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          W 1 Reply Last reply Reply Quote 0
          • W
            Walux @Joel Bodenmann last edited by

            @Joel-Bodenmann

            Huge thanks for your support , i got one step forward to solving my problem thanks to your advices .

            Taking things from beginning to end : That's my entertainment !

            1 Reply Last reply Reply Quote 0
            • W
              Walux last edited by

              I had misconfigured ensureVisible's margins , and the view's size and the scene's rect .
              Now it works fine :)

              Taking things from beginning to end : That's my entertainment !

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