Results 1 to 5 of 5

Thread: QGraphicsView and QGraphicsScene geometry

  1. #1
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView and QGraphicsScene geometry

    Hello.

    I need some tips from my fellow programmers. I am working with QGraphicsView and QGraphicsScene as the title implies and what I need some tips with is how to size/scale QGraphicsScene in proportion to the view.

    What I have now is a view widget that expands as the window expands and fixed size to the scene. But what I want is the same behavior for the scene as a widget has when it expands with the mainwindow. And I am not sure how to do this in a effective way. I am thinking about scaling but do not know if there are better ways.

    I have attached a picture to try and clarify what I want. If you look at the picture, I want the items in the scene have the same proportions when I maximize the window.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView and QGraphicsScene geometry

    I am thinking about scaling but do not know if there are better ways.
    yes, scaling is the way to go.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    meazza (9th May 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and QGraphicsScene geometry

    Reviving this thread again instead of starting a new one so hopefully someone is gonna answer. What I am trying to accomplish is what is stated in my first post here. When I change the size of my window I want the items to have the same proportions.

    Trying to implement this I came across a problem. What I do is in QGraphicsView::resizeEvent() I re-position and resize all the items in the scene depending on the size of the QGraphicsView change in procent. And this works ok, not fully happy so if you have some other suggestion I would gladly listen.

    But my main question here is possible to set some kind of size policy on a widget so it is always a square. In this situation I want my QGraphicsView to always have equal width and height. But I dont know if I like that idea. The problem here is that tachometer item that you see on the attached picture needs to stay as a square or it gets deformed and that is where I got the idea of keeping the QGraphicsView square.

    Dont know if I am making any sense here, has been a long day and this will be the last thing I do today

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,387
    Thanks
    247
    Thanked 687 Times in 677 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QGraphicsView and QGraphicsScene geometry

    In your resize event, you could try a call to

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

    This will maintain the same relative sizes and aspect ratio of everything in the scene, *except* those items with the QGraphicsItem::ItemIgnoresTransformations flag set. So if your tach's rect is square in scene coordinates, it will be square in the view.

  6. The following user says thank you to d_stranz for this useful post:

    meazza (4th July 2011)

  7. #5
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and QGraphicsScene geometry

    Quote Originally Posted by d_stranz View Post
    In your resize event, you could try a call to

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

    This will maintain the same relative sizes and aspect ratio of everything in the scene, *except* those items with the QGraphicsItem::ItemIgnoresTransformations flag set. So if your tach's rect is square in scene coordinates, it will be square in the view.
    Thank you very much, this was what I was looking for

Similar Threads

  1. QGraphicsScene & QGraphicsView help please
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 13th February 2017, 12:30
  2. QGraphicsView and QGraphicsScene
    By Molier in forum Qt Programming
    Replies: 11
    Last Post: 28th November 2010, 01:23
  3. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 10:10
  4. QGraphicsScene and QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 1st August 2007, 06:59
  5. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43

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.