Results 1 to 6 of 6

Thread: Resize QGraphicsItem when window resizes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resize QGraphicsItem when window resizes

    First of all, thank you for the help.

    I am using the QGraphicsView inside a QGridLayout and it resizes fine. My problem is that I need to resize the itens inside a QGraphicsScene that is inside the view. I need the itens resizing when the view is resized. Could you help me in this?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,323
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Resize QGraphicsItem when window resizes

    Implement resizeEvent() for the widget that holds the QGraphicsView. Maybe this is the MainWindow of your class. In that event handler, retrieve the QRect of the QGraphicsView (not the QRect passed in the event - that's the rect for the entire main window), then call QGraphicsView::fitInView() with that QRect. If you want the objects in the view to stretch the same in both directions (squares remain square, circles remain circular), then use the Qt::AspectRatioMode value Qt::KeepAspectRatio, otherwise it will stretch differently in horizontal vs. vertical dimensions - squares will become rectangles, circles will become ellipses, etc.

Similar Threads

  1. Replies: 1
    Last Post: 29th December 2013, 18:06
  2. Replies: 2
    Last Post: 5th February 2012, 17:44
  3. Replies: 7
    Last Post: 1st December 2011, 16:24
  4. Replies: 4
    Last Post: 20th April 2011, 02:46
  5. resize a QGraphicsItem
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 09:58

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.