Results 1 to 5 of 5

Thread: Grid in QGraphicsScene to fit in QGraphicsView while expanding

  1. #1
    Join Date
    Mar 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Grid in QGraphicsScene to fit in QGraphicsView while expanding

    Hi,

    I want to draw a grid (square), and this grid has to remain square and grow up, while the view is expanding.

    I used setSceneRect but it is weird. This example below shows what I'm looking for, the width of the windows is larger than the height, so my grid
    grow up and remain square.

    And I didn't know how to do this with Qt. Bellow I've done it with direct2D...
    square2.PNG

    need your help...

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grid in QGraphicsScene to fit in QGraphicsView while expanding

    The easiest way is to simply scale the view using QGraphicsView::fitInView() called from within resizeEvent of the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Grid in QGraphicsScene to fit in QGraphicsView while expanding

    it seems to work.

    Qt Code:
    1. GraphicsView->fitInView( scene->sceneRect(), Qt::KeepAspectRatio );
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot

  4. #4
    Join Date
    Mar 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Grid in QGraphicsScene to fit in QGraphicsView while expanding

    Hi,

    this time, when I drew 1000 squares grid with 1pixel each square, this doesn't fit in my GraphicsView,

    I got blank scene... my screen resolution is around 1000 pixels, if I reduced to 800 squares, I got all my grid back.

    What I don't understand is I can't draw more than 1000 pixels whatever my GraphicsView's size...

    bellow 800 squares fit correctly in 300pixels GraphicsView's size
    with 1000 squares all I got is blank even with 900 pixels GraphicsView's size(with my view expanded at maximum)
    800.PNG

    Any tips please ?
    Last edited by phenom64; 9th May 2014 at 09:39.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grid in QGraphicsScene to fit in QGraphicsView while expanding

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 11th July 2011, 20:39
  2. How can I stop expanding a QGraphicsScene?
    By emrares in forum Newbie
    Replies: 2
    Last Post: 2nd November 2010, 15:27
  3. QGraphicsScene auto expanding.
    By miqqo in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2010, 21:56
  4. Replies: 5
    Last Post: 21st January 2010, 15:55
  5. How Coulld I create a Grid Layout on a QGraphicsScene
    By c_srikanth1984 in forum Qt Programming
    Replies: 3
    Last Post: 12th January 2009, 10:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.