Results 1 to 8 of 8

Thread: how to zoom out item in View/Scene

  1. #1
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation how to zoom out item in View/Scene

    Hi,

    I have GraphicsView/Scene, having multiplpe items in it.
    I want to zoom in the view but as the same time I dont want to zoom in the items in scene.
    Only background shoud zoom in not the items inside it.
    How to I achieve this. ??

    Thanks,
    Nilesh

  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: how to zoom out item in View/Scene

    A strange requirement You can try setting QGraphicsItem::ItemIgnoresTransformations on your items. Or you can reimplement drawBackground() for your view.

  3. #3
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to zoom out item in View/Scene

    Thanks for solution,
    I have tried QGraphicsItem::ItemIgnoresTransformations, but If I zoom view with items (say in some ratio) and then I set QGraphicsItem::ItemIgnoresTransformations flag for all items, then all item's shape gets changed to original shape.
    e.g. If initial view's zoom scale = 1.0
    1st zoom in, scale = scale * 1.2
    2nd zoom in, scale = scale * 1.2
    and then I set flag QGraphicsItem::ItemIgnoresTransformations fro all items then
    items shape gets changed to when scale was 1.
    I dont want this behaviour, whatever the last zoom size shoud maintinan same for next zoom in.
    How I coud get the item's painter's scale because I have checked and found that in paint(..) fucntion painter's martix gets changed, I want painter's martix before I could set up QGraphicsItem::ItemIgnoresTransformations flag.
    Which evet gets fired for this flag. ?????
    How could I use the drawBackground() to achieve this ??

  4. #4
    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: how to zoom out item in View/Scene

    Quote Originally Posted by nileshsince1980 View Post
    and then I set QGraphicsItem::ItemIgnoresTransformations flag for all items, then all item's shape gets changed to original shape.
    Set the flag right after creating each item.

    I dont want this behaviour, whatever the last zoom size shoud maintinan same for next zoom in.
    You said you wanted your background to scale and items to remain the same. Isn't it what you got?

    How could I use the drawBackground() to achieve this ??
    I'm not sure what you want to achieve, so it's hard for me to propose a solution. If you tried to explain what effect you want to obtain, maybe it'd be easier to find a solution.

  5. #5
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to zoom out item in View/Scene

    Let me explain again,
    I want to switch on/off feature of freezing item zoom.
    So whenever I switch on( ItemIgnoresTransformations is true), and the do (zoom in/out) operations, items should not get zoom in/out accordingly.

    e.g. Consider following sequence of operations,
    1. Initial view's scale = 1.00
    QGraphicsItem's painter scale = 1.00
    2. Operation = zoom in view
    View's scale = 1.0 * 1.2 = 1.2
    GraphicsItem's painter scale = 1.20
    3. Operation = zoom in view
    View's scale = 1.2 * 1.2 = 1.44
    GraphicsItem's painter scale = 1.44
    4. Operation = Freez item zoom
    View's scale = 1.44 but
    GraphicsItem's painter scale = 1.00
    5. Operation = zoom in
    View's scale = 1.44 * 1.2 = 1.73
    GraphicsItem's painter scale = 1.00

    So at step 4, GraphicsItem's painter scale = 1.00, which I don’t want, whatever is last
    GraphicsItem's painter scale should remain as it is for next subsequent operations.
    In this case, step 4 & 5 should have become like,
    4. Operation = Freez item zoom
    View's scale = 1.44 but
    GraphicsItem's painter scale = 1.44
    5. Operation = zoom in
    View's scale = 1.44 * 1.2 = 1.73
    GraphicsItem's painter scale = 1.44

  6. #6
    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: how to zoom out item in View/Scene

    I don't think this is easily achievable and I admit I don't know what you need it for. What you can try is to create a QGraphicsItemGroup when you want to "freeze" items, put all items into the group and make the group item ignore transformations. I don't know if you'll obtain the effect you seek for but based on your explanation, it should be something like that.

  7. #7
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to zoom out item in View/Scene

    In my case GraphicsItem's painter scale means

    Qt Code:
    1. GraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    2. {
    3. m = painter->matrix();
    4. // draw rect
    5. painter->drawRect(rect);
    6. }
    To copy to clipboard, switch view to plain text mode 

    I have checked the matrix (m = painter->matrix()) which is gets reset when I set flag ItemIgnoresTransformations.
    You can check painter's scale changes by creating simple applcation with GraphicsView/Scene and adding some rects/ellipse in it. and then zooming for 3 times and then setting ItemIgnoresTransformations flag for all items. You can observe matrix (m) changes.

    Can you tell me which events gets send to GraphicsItem when view's matrix get changed.
    other than paint(...) ??

  8. #8
    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: how to zoom out item in View/Scene

    But why do you want to paint the background using the graphics view architecture if you immediately disable all it gives you.

    As for the event, take a look at QGraphicsItem::itemChange().

Similar Threads

  1. Replies: 1
    Last Post: 19th April 2007, 23:23
  2. Zoom Options
    By Kapil in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 12:19
  3. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 02:34

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.