Results 1 to 14 of 14

Thread: QGraphicsView keep aspect ratio of items when scaled

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    70
    Thanked 59 Times in 57 Posts

    Default QGraphicsView keep aspect ratio of items when scaled

    Hi,

    I'm trying to use QGraphicsView and QGraphicsScene to do represent a plastic film that is 0.3meter width and 100meter height. In this plastic film there are some marks that I want to show to the user. The problem is that the aspect ratio of the film. Using the "fitInView" method keeping the aspect ratio gets me a view like you can see on the attached image.
    keepAspectRatio.PNG
    The black line is the rectangle that represents the full scene.

    Without keeping the aspect ratio I get what I want but with the problem that the items also don't keep their aspect ratio, so a circle is displayed as an ellipse.

    What I need is to show the full scene into the view(sure that will not keep the aspect ratio) but show the items with the original aspect ratio.

    Thanks,

    P.D.: I don't want the scroll bars to be used. This is why I want to show the full scene fitting the view.

    Maybe the use of Qwt will be simple as I only want to let the user to pick the marks to show more information.
    Last edited by ^NyAw^; 29th January 2013 at 11:19.
    Òscar Llarch i Galán

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

    Default Re: QGraphicsView keep aspect ratio of items when scaled

    One thing is that you can always hide scrollbars if you don't want them. Another thing is that you can pass KeepAspectRatioByExpanding to fitInView.
    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
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    70
    Thanked 59 Times in 57 Posts

    Default Re: QGraphicsView keep aspect ratio of items when scaled

    Hi,

    What i need is to full fit the scene into the view but also need to display the items keeping the original aspect ratio. This is, when I add a square rectangle I want it to be displayed square or if I add a circle I want it to be showed as a circle, not an ellipse.

    Passing KeepAspectRatioByExpanding the scene will get out of the view limits(as I understand).

    Thanks,
    Òscar Llarch i Galán

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

    Default Re: QGraphicsView keep aspect ratio of items when scaled

    I think your requirements are contradictory. You want to display something that doesn't fit your display in a way that it fits your display but without reducing the size in the other dimension at the same time keeping the aspect ratio. This is simply not possible. Either the larger dimension will not fit into the view, the smaller dimension will have to be scaled down or the aspect ration will have to be ignored.
    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. Get aspect ratio from Phonon videoWidget
    By budda in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2012, 09:46
  2. Printing and Aspect ratio
    By cpt4 in forum Qwt
    Replies: 9
    Last Post: 30th September 2011, 15:28
  3. keeping aspect ratio while resizing
    By franco.amato in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 21:12
  4. Preserving aspect ratio of image
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2009, 14:39
  5. aspect ratio of top-level widgets
    By urbangipsy in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2007, 22:49

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.