Results 1 to 2 of 2

Thread: Independent scaling behavior for QGraphicsItems

  1. #1
    Join Date
    May 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Independent scaling behavior for QGraphicsItems

    I am writing a program to display and export specialized graph data. The graphs are fairly non-standard, so I suspect that Qwt is not an option. As a result, I want to be able to draw these graphs myself.

    The problem is that I need to be able to do a selection zoom (QRubberBand) on an area, scaling the graph elements in that area, but leaving the axes exactly where they are and simply redraw the axis labels accordingly. I assume that I cannot use QGraphicsView's scaling, as I don't want scrollbars. So the scene must be redrawn whenever zooming occurs.

    What is the best way to ensure that each item will be redrawn according to the new zoom level? Do I group items with the same behavior? Do I write a specialized QGraphicsScene class to handle the scaling of each item?

    I can't find any good examples to get started with, so any help would be appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Independent scaling behavior for QGraphicsItems

    Attached is a picture.

    On the left, you select a part of the chart (or graph, in green) with a rubberband (in grey).
    The actual size of the canvas that displays your axes (in black) and chart remains the same (see the chart on the right).
    What you do is calculate where the rubberband intersects the chart (see orange points on the left and the right) and redraw the chart in the bounding box of the chart canvas (using control points, see orange points) and adjust the scale on the axes (redraw them).

    So, you basically provide a chart canvas, consisting of axes and an actual chart (all seperate objects).
    The use a rubber band on your canvas. Calculate the intersections with your actual chart. Resize your actual chart within the canvas (as in redraw within the bounding box, don't draw outside of it) and adjust the axes.

    Is this clear enough?
    There might be other ways too of course.
    Attached Images Attached Images

Similar Threads

  1. QRegExp independent subexpressions
    By Nik8768 in forum Newbie
    Replies: 9
    Last Post: 18th April 2010, 23:28
  2. Scale independent QGraphicsItem
    By Twoslick in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2010, 05:59
  3. Platform independent GUI
    By bnilsson in forum Qt Programming
    Replies: 39
    Last Post: 28th November 2009, 11:00
  4. Independent Right-Click Menus
    By HiFly in forum Qt Programming
    Replies: 5
    Last Post: 20th February 2009, 07:58
  5. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 21:30

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.