Results 1 to 7 of 7

Thread: Detect changes to the Viewport in QGraphicsView on resize

  1. #1
    Join Date
    Nov 2016
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default 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?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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?
    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().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Mar 2014
    Posts
    23
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Detect changes to the Viewport in QGraphicsView on resize

    Quote Originally Posted by d_stranz View Post
    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.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Detect changes to the Viewport in QGraphicsView on resize

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Nov 2016
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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!

Similar Threads

  1. Replies: 1
    Last Post: 20th January 2016, 07:30
  2. Detect changes to the Viewport in QGraphicsView
    By Casper14 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2014, 11:21
  3. how to detect if QGraphicsTextItem is inside viewport
    By mihnen in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2012, 03:57
  4. Replies: 5
    Last Post: 9th January 2012, 21:22
  5. Replies: 3
    Last Post: 11th December 2011, 10:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.