How to set definite Scene Rect in QGraphicsView.
Hi All,
I am developing a application in which I am adding no of items into the scene. I know that by default view shows the item in the center. thats fine with my application. Now when I try to animate the items with setPosAt to move the items all the items gets togather at the center of the view overlapping eachother. I think this is the problem with SceneRect. Now I need to set the definitive scene rect . I have tried it to set using setSceneRect but it doesn't worked. Can anyone please help me out. Do I need to subclass QGraphicsScene class inorder to override setSceneRect.
Thanks and Advance.
Re: How to set definite Scene Rect in QGraphicsView.
I dont think its prob with scene rect.
You might be making some mistake while placing the items. Can we see what u are trying ??
Re: How to set definite Scene Rect in QGraphicsView.
Thanks for your reply..
Here is the code.. Can you please tell me how can I scale the two rects at the center.
Code:
#include <QtGui/QApplication>
#include "animation.h"
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItemAnimation>
#include <QGraphicsEllipseItem>
#include <QTimeLine>
#include "windows.h"
int main(int argc, char *argv[])
{
//Animation w;
//w.show();
Rect->setZValue(-1);
timer->setFrameRange(0, 100);
animation->setItem(ball);
animation->setTimeLine(timer);
animation1->setItem(Rect);
animation1->setTimeLine(timer);
scene->addItem(ball);
//scene->addItem(ecl);
scene->addItem(Rect);
view->setAlignment(Qt::AlignCenter);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setGeometry(10,10,900,700);
view->show();
//timer->start();
QRectF rc
= ball
->mapToScene
(ball
->boundingRect
()).
boundingRect();
QRectF rc1
= ecl
->mapToScene
(ecl
->boundingRect
()).
boundingRect();
QRectF rc2
= Rect
->mapToScene
(Rect
->boundingRect
()).
boundingRect();
for (int i = 0; i < 200; ++i)
{
//animation->setTranslationAt(i/200.0, rc.width()/2.0,rc.height()/2.0);
animation->setScaleAt(i/200.0, 1 + i/200.0, 1 + i/200.0);
//animation->setTranslationAt(i/200.0, -( rc.width()/2.0 + i/200.0), -rc.height()/2.0);
animation
->setPosAt
(i
/200.0,
QPointF(150.0 - i
/200.0, rc.
top()));
}
for (int i = 0; i < 200; ++i)
{
//animation1->setTranslationAt(i/200.0, -i/200.0,0);
animation1->setScaleAt(i/200.0, 1 + i/200.0, 1 + i/200.0);
//animation1->setTranslationAt(i/200.0, -rc2.width()/2.0, -rc2.height()/2.0);
animation1
->setPosAt
(i
/200.0,
QPointF(150.0 -i
/200.0, rc2.
top()));
}
rc = ball->mapToScene(ball->boundingRect()).boundingRect();
rc1 = ecl->mapToScene(ecl->boundingRect()).boundingRect();
rc2 = Rect->mapToScene(Rect->boundingRect()).boundingRect();
//scene->addItem(Rect);
//scene->setSceneRect(10, 10, 900, 700);
return a.exec();
}