views:

52

answers:

1

Hi,

I have a QGraphicsView. To that I added a QGraphicsScene and to that a added an QPixmap(*.jpeg) and QGraphicsEllipseItem(a circle). The QPixmap is much more bigger than the QGraphicsView, so scrolling is enabled. The problem is that both QPixmap and QGraphicsEllipseItem are moving. But I want a fixed position for the QGraphicsEllipseItem in QGraphicsView. It should always be in the center of the QGraphicsView. How can I do that? Hope someone can help.

+1  A: 

Add a signal handler for the scroll signal of the scroll bars (use QAbstractSlider::sliderMoved()).

Then you can query the view for it's left/top offset and size and position the circle accordingly. See the explanation for QAbstractScrollArea to get you started.

Aaron Digulla
I tried, but I don't get any signal. But I will still try it. And thank you.
Ok, it works with graphicsView.viewport().installEventFilter(self) and graphicsView.setViewportUpdateMode(0). Now it is possible to catch the mouseMove event. It's not the best way to go, but it works.
I wouldn't catch a mouse move. Afetr all, what if you later need to move the view programaticaly? There won't be a mouseMove to catch. Better to bind to the scrollbar signals.
Simon Hibbs