Results 1 to 7 of 7

Thread: How to use QGraphicsView and Scene right ...

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to use QGraphicsView and Scene right ...

    Hi all,

    I would like to get your feedback on how I should use QGraphicsView for a technical application.
    I plan to render graphs that have X and Y axis that both render a range from 0..100. The Y-Axis does this for % and the X-Axis for msec.
    I started to render the axis but 'am not 100% sure how to do it right. If you specify e.g. the x-axis to be 400 pixel long, and the y axis 200 pixel high, than that's what you get. Meaning what I really want is that the scene alway's takes up the most available space in the view. This is important if the user resizes the application window. So if I start like this:

    #######################
    # ^
    # |
    # |
    # +---------------------------------->#
    #######################

    Now the user changes the size of the view:

    ############################
    # ^
    # |
    # |
    # |
    # |
    # +------------------------------------------->#
    ############################

    Then I still want the scene to render correctly in all the available space of the view. Zooming doesn't really do the job, because the ratio between available pixel in y direction may differ from the x axis...

    Also the scene does require you to specify fixed lengh parameters for e.g. a addLine method. I really wonder if i have to clear all graphics items in the scene when the user changes the size of the view... get the available space from the view and then render the scene again.

    How would you use the QGraphicsView / Scene for this? Any suggestion?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QGraphicsView and Scene right ...

    Quote Originally Posted by Mike View Post
    I would like to get your feedback on how I should use QGraphicsView for a technical application.
    I plan to render graphs that have X and Y axis that both render a range from 0..100. The Y-Axis does this for % and the X-Axis for msec.
    Maybe you should try Qwt? It should have all the functionality you need and it's LGPL.

    Quote Originally Posted by Mike View Post
    Zooming doesn't really do the job, because the ratio between available pixel in y direction may differ from the x axis...
    It doesn't? You can pass two different scaling factors to QGraphicsView::scale().

    And how about this?
    Qt Code:
    1. _ui.view->fitInView( _ui.view->scene()->sceneRect() );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QGraphicsView and Scene right ...

    Hi thanks. I missed this code:

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

    It's maybe not perfect with text.. but for the graph I want to render it looks pretty good. Maybe this single line of code is really all I need.

    Great!

  4. #4
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QGraphicsView and Scene right ...

    I have a similar problem and for me scaling doesn't do the job.

    My current approach is to reimplement the resizeevent of whatever widget the graphicsview is in and set the scene rect based on the dimensions of the graphicsview. I have to take 2 pixels off to avoid scroll bars or alternatively turn the scroll bars off.

    Maybe that is an alternative to using scaling factors?

    Andreas

    PS: Is GWT Plot already using QGraphicsView and item detection, e.g. if you want to click on a line plot to probe for properties?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QGraphicsView and Scene right ...

    Well I have to admit, that I did try to use QGraphicsview, but with scaling the rendered text (labels for x and y axis) did look pretty ugly... so I'm also still looking for another approach. I haven't seen a way for scaling the graphics but not the text... so I'm currently back to rendering the stuff myself depending on the available pixels (width & height)

    Maybe some sample - if someone solved this with QGraphicsview would be great...

    Until then, I paint everything myself...

  6. #6
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QGraphicsView and Scene right ...

    If you're referring to fitInView()'s default behavior of scaling without keeping the aspect ratio, you can pass Qt::KeepAspectRatio as a second argument. Otherwise, this function shouldn't distort text rendering at all.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: How to use QGraphicsView and Scene right ...

    Well today I had to smile... I saw this post on qtdeveloper.net:

    http://blogs.qtdeveloper.net/archive...m-tags-labels/

    Apparently more people had the same problem than me, and now one would be able to keep lables and X / Y axis unchanged when resizing the GraphicsView. That is great news and I'm looking forward to the next Qt release to try it out...

    Thanks Trolltech for listening to your users !

Similar Threads

  1. QGraphicsView and QGraphicsScene speeds
    By jnk5y in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2006, 07:13
  2. QGraphicsView and contextMenuEvent
    By laurabee in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2006, 22:22
  3. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 10:56
  4. Examples of QGraphicsView
    By grosem in forum Newbie
    Replies: 16
    Last Post: 22nd August 2006, 21:48

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.