PDA

View Full Version : Problem with QGraphicsView and ItemIgnoresTransformations



coderCPP1981
25th June 2008, 08:29
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.


QGraphicsScene *m_scene = new QGraphicsScene;
const QPixmap *pic = new QPixmap( "/home/bargi/aa.png" );
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem( pic );
m_scene->addItem(pixmapItem );


For creating View:



View::View( QWidget *parent )
: QGraphicsView( parent )
{
QGraphicsScene *m_scene = new QGraphicsScene;
setScene( m_scene );}


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:



pixmapItem->setFlag(QGraphicsItem::ItemIgnoresTransformations) ;



"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 :(

aamer4yu
25th June 2008, 18:01
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.

coderCPP1981
26th June 2008, 07:05
Thanks for reply aamer4yu....

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

Actually m_scene is created only once in view class.




View::View( QWidget *parent ) : QGraphicsView( parent )
{
QGraphicsScene *m_scene = new QGraphicsScene;
setScene( m_scene );
}


After this in Draw class I access m_scene using code:



view->scene();


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 :)

aamer4yu
26th June 2008, 07:57
Can u show the code what are u doing on zoom ? and how are u zooming ?

coderCPP1981
26th June 2008, 10:19
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:



void View::zoomIn()
{
scale( 1.25,1.25 );
emit zoom();
}


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:


QGraphicsItemGroup *group = new QGraphicsItemGroup;
QPointF vertex;
const QPixmap *pic = new QPixmap( "/home/bargi/aa.png" );
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem( pic );
vertex = QPointF( coordinate x, coordinate Y );
pixmapItem->setOffset ( vertex );

group->addToGroup( pixmapItem );

return group;



And this return group is used in some function say Draw_item() and add to scene as follow:


m_scene->addItem( group );


These are the things included in drawing Pixmap.

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

Thanks

aamer4yu
26th June 2008, 16:05
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 ??

coderCPP1981
27th June 2008, 05:28
I have done what you suggest....
Now only images are drawn once ........but the result is same :confused:
I think that there is some problem in view or scene ...
We are missing something.........
Do u have any idea ??

Thanks