PDA

View Full Version : Detect changes to the Viewport in QGraphicsView on resize



tamara3011
1st November 2016, 17:42
Hi All,

I am trying to detect changes to the viewport of my QGraphicsView. I am able to get movement by looking at the valueChanged signal from the scroll bars. But how can I also get resize events. Sometime a resize causes the scrollbar position to change but not always.

Any suggestions? I would rather not have to subclass if I don't need to. Essentially all I want it to know anytime the viewport->rect() changes.

What I am trying to do is look at the same scene with 2 different QGraphicsView windows and show on one view where the viewport is located in the other view ( one is zoomed in, the other is scaled to fit display )

Thanks

anda_skoa
1st November 2016, 18:02
If you don't want to derive from QWidget to use as a custom viewport, you could use an event filter.
See QObject::eventFilter().

Cheers,
_

Killian
2nd November 2016, 14:11
Why don't you just overwrite the resizeEvent of the QGraphicsView if that's all you want to get notified of?

d_stranz
2nd November 2016, 15:43
Why don't you just overwrite the resizeEvent of the QGraphicsView if that's all you want to get notified of?

If that's all the OP wants, then using an event filter as anda_skoa suggests avoids the need to derive a new class from QGraphicsView just to handle resizeEvent().

Killian
2nd November 2016, 17:05
If that's all the OP wants, then using an event filter as anda_skoa suggests avoids the need to derive a new class from QGraphicsView just to handle resizeEvent().

Sure thing, I just assumed he'd use a custom class anyway.
After reading OP's post again that assumption seems kinda absurd. Your objection is valid.

d_stranz
3rd November 2016, 02:16
Your objection is valid

Not so much an objection as an observation that there are many ways to skin Qt cats. Event filters are one of the more difficult things to understand about Qt event processing, whereas deriving a class and overriding a virtual method is straightforward.

tamara3011
3rd November 2016, 14:24
Hi All,

Thanks for the replies, Using the event handler has worked for me. I did not want to subclass my dialog box if I didn't need to. Wanted to know when ever the viewport location changed within a scene ( scrolling, dragging, scaling, resize, etc) this worked for me.

Thanks!