Results 1 to 7 of 7

Thread: Problem with QGraphicsView and ItemIgnoresTransformations

  1. #1
    Join Date
    Jun 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with QGraphicsView and ItemIgnoresTransformations

    Hi ,

    I am facing the problem with zooming functionality of QGraphicsView.

    I have to draw images on QGraphicsView and for that I have used the following code.
    Qt Code:
    1. const QPixmap *pic = new QPixmap( "/home/bargi/aa.png" );
    2. QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem( pic );
    3. m_scene->addItem(pixmapItem );
    To copy to clipboard, switch view to plain text mode 

    For creating View:

    Qt Code:
    1. View::View( QWidget *parent )
    2. : QGraphicsView( parent )
    3. {
    4. setScene( m_scene );}
    To copy to clipboard, switch view to plain text mode 

    But the image was increasing its size on zoomIn and decreasing on zoom out.
    I want that its size should remain constant.For this I have used some flags related to QGraphicsPixmapItem. The code is below:

    Qt Code:
    1. pixmapItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
    To copy to clipboard, switch view to plain text mode 


    "ItemIgnoresTransformations" flag should ignore all the transformation applied on it like zoomIn or zoomOut.
    But doing this lead to strange behavior, now when I zoomIn on image its hide to some extent on every click of ZoomIn and hide all at particular level.

    I am not able to understand why this is happening.
    I have attached the screenshot in which the images are shown at different zoom level.

    In first u will see that images are drawn properly. In second and third you see the change that images are hiding on every zoomIn click.
    In 4th image ,some images are partially hide.When I scroll the vertical or horizontal scroll bar they semi-hide images are shown properly.
    I can't understand this behavior.
    Also, when I comment "itemignoretransformation" it doesn't hide the images but increase there size which I don't want.

    CAn any body help me in solving this problem????

    Any queries are most welcome ??

    Thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    How many times are u creating scene ??
    where is m_scene declared and defined ?? Make sure u are not messing it.
    Cant say much from the code given

    Also for problems related to scene, i suggest draw bounding rect in the paint function of the graphics item, this will give u some idea what is overlapping and whats not.

  3. #3
    Join Date
    Jun 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    Thanks for reply aamer4yu....

    I am sorry for giving incomplete information.....

    Actually m_scene is created only once in view class.

    Qt Code:
    1. View::View( QWidget *parent ) : QGraphicsView( parent )
    2. {
    3. setScene( m_scene );
    4. }
    To copy to clipboard, switch view to plain text mode 

    After this in Draw class I access m_scene using code:

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

    And it return the scene created,since view inherits QGraphicsView.

    Also as you suggest me to calculate the boundingRect(), I have done this and found that, on zooming the boundingrect() of each item is not increasing i.e it remains same and I think that boundingrect() of each item is not overlapping with other( what I think).
    I am researching on this issue.Any help will be greatly appreciated.

    Thanks once again

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    Can u show the code what are u doing on zoom ? and how are u zooming ?

  5. #5
    Join Date
    Jun 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    Thanks for reply.....

    Actually the flow is like this:

    In view.h I have create a slot:
    public slots:
    void zoomIn();
    This slot is connected to zoomIn icon on toolbar. When I clicked on it , a signal is fired and zoomIn slot is called and inside it I have used scaling as follow:

    Qt Code:
    1. void View::zoomIn()
    2. {
    3. scale( 1.25,1.25 );
    4. emit zoom();
    5. }
    To copy to clipboard, switch view to plain text mode 

    emit zoom() is connected to the slot "DrawImages()" in Draw class.

    In this function images are drawn one by one on particular coordinates.
    The coordinates are used as follow:
    Qt Code:
    1. QPointF vertex;
    2. const QPixmap *pic = new QPixmap( "/home/bargi/aa.png" );
    3. QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem( pic );
    4. vertex = QPointF( coordinate x, coordinate Y );
    5. pixmapItem->setOffset ( vertex );
    6.  
    7. group->addToGroup( pixmapItem );
    8.  
    9. return group;
    To copy to clipboard, switch view to plain text mode 

    And this return group is used in some function say Draw_item() and add to scene as follow:
    Qt Code:
    1. m_scene->addItem( group );
    To copy to clipboard, switch view to plain text mode 

    These are the things included in drawing Pixmap.

    Hope this have clear the picture.If any doubts remain plz let me know .....

    Thanks

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    emit zoom() is connected to the slot "DrawImages()" in Draw class.

    In this function images are drawn one by one on particular coordinates.
    Why do u need to draw pics again :O
    I guess u just need to scale, and rest will be taken care by view...

    just comment - emit zoom() and see what happens ??

  7. #7
    Join Date
    Jun 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QGraphicsView and ItemIgnoresTransformations

    I have done what you suggest....
    Now only images are drawn once ........but the result is same
    I think that there is some problem in view or scene ...
    We are missing something.........
    Do u have any idea ??

    Thanks

Similar Threads

  1. QGraphicsView Problem
    By hakkman in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2008, 20:27
  2. QGraphicsView Problem !!
    By Gamalof in forum Qt Programming
    Replies: 3
    Last Post: 14th June 2008, 13:55
  3. Mystic Problem (QGraphicsView + QGLWidget)
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:39
  4. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 14:54
  5. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18

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.