Important: Please read the Qt Code of Conduct -

[Solved]Qt QGraphicsItem - always in center of QGraphicsView

  • Hi? I am back with this issue: I've got inherited class QGraphicsItem, which is added & displayed on QGraphicsView, but it's always at center (I can't move with it)...How to solve this problem?

    I've tried QGraphicsItem->moveBy(...) but didn't work...

  • Sounds like you are not explicitly setting a sceneRect on your scene. If you do not explicitly set a scene rect then the QGV framework calculates one for you and with just one item it will appear as if that item is centered in the view.

    Try calling QGraphicsScene::setSceneRect() with a suitable boundng rectangle.

    If you wish to move an item with the mouse then you need to enable the QGraphicsItem::ItemIsMovable flag too.

  • Yes it works properly now, thanks.

Log in to reply