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. How to move all QGraphicsObject in QGraphicsScene to center?
Forum Updated to NodeBB v4.3 + New Features

How to move all QGraphicsObject in QGraphicsScene to center?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.8k Views 4 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I have a collection of QGraphicsObject in a QGraphicsScene. At the moment of creating the QGraphicsScene, I would like to position the center of all QGraphicsObjects together as a group (i.e, keeping the relative positions of the individual QGraphicsObechts) to the center of the QGraphicsScene. Any idea how I can do this easily?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean put all your graphic objects on top of each other on the centre of the scene ? Or put them all together in one big rectangle and have that thing centred in your 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
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        I mean the latter: take all together as a group and put it centered on the scene. I thought I had it figured out with (QGraphicsScene::itemsBoundingRect()).moveCenter(QPointF(0, 0)) but this does not seem to do anything.

        Chris KawaC 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Ok

          Can you show how you are doing it currently ?

          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
          • ModelTechM ModelTech

            I mean the latter: take all together as a group and put it centered on the scene. I thought I had it figured out with (QGraphicsScene::itemsBoundingRect()).moveCenter(QPointF(0, 0)) but this does not seem to do anything.

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ModelTech said in How to move all QGraphicsObject in QGraphicsScene to center?:

            I thought I had it figured out with (QGraphicsScene::itemsBoundingRect()).moveCenter(QPointF(0, 0)) but this does not seem to do anything.

            It does something, just not what you want to ;) itemsBoundingRect() returns a rectangle. moveCenter() moves that rectangle. It has nothing to do with moving any objects ;)

            What you need to do is get the itemsBoundingRect(), then take its center() and then for each item in the scene moveBy() a negative value of the center you got earlier.

            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