Detect changes to the Viewport in QGraphicsView on resize
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
Re: Detect changes to the Viewport in QGraphicsView on resize
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,
_
Re: Detect changes to the Viewport in QGraphicsView on resize
Why don't you just overwrite the resizeEvent of the QGraphicsView if that's all you want to get notified of?
Re: Detect changes to the Viewport in QGraphicsView on resize
Quote:
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().
Re: Detect changes to the Viewport in QGraphicsView on resize
Quote:
Originally Posted by
d_stranz
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.
Re: Detect changes to the Viewport in QGraphicsView on resize
Quote:
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.
Re: Detect changes to the Viewport in QGraphicsView on resize
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!