hi,
I 'm trying to make a queue of QGraphicsRectItems on the scene after have moving each of them forwards .I used the QGraphicsItemGroup but i cannot run it.
may someone help me to solve this problem please?
thanks in advance.
the code looks like this:
Container.h
{
Q_OBJECT
public:
void advance();
private:
};
class Container: public QGraphicsRectItem
{
Q_OBJECT
public:
Container(QGraphicsItem* parent=0, int x, int y);
void advance();
private:
QGraphicsItemAnimation *anim;
QTimeLine * timeline;
};
To copy to clipboard, switch view to plain text mode
Container.cpp
#include"container.h"
Qpen p(color);
p.setWidht(2);
setRect(x,y,100,60);
show();
}
Container::advance(){
anim->setItem(this);
for (qreal i=0.0;i<500.0;i++){
anim->setTranslationAt(i/500.0,0.0,i);
}
anim->setTimeLine(timeline);
timeline->setUpdateInterval(1000/10);
timeline->setLoopCount(1);
timeline->setDuration(50000);
}
#include"container.h"
Container::Container(QGraphicsItem* parent, int x=0, int y=0):QGraphicsRectItem(parent)
{QColor color(0,0,100);
Qpen p(color);
p.setWidht(2);
QBrush(brush);
setRect(x,y,100,60);
show();
}
Container::advance(){
anim= new QGraphicsItemAnimation();
timeline= new QTimeLine(5000);
anim->setItem(this);
for (qreal i=0.0;i<500.0;i++){
anim->setTranslationAt(i/500.0,0.0,i);
}
anim->setTimeLine(timeline);
timeline->setDirection(QTimeLine::Backward);
timeline->setUpdateInterval(1000/10);
timeline->setLoopCount(1);
timeline->setDuration(50000);
}
To copy to clipboard, switch view to plain text mode
MainGui.h
{
public:
MainGui(...);
private:
};
class MainGui: public QWidget
{
public:
MainGui(...);
private:
QGraphicsScene *scene;
QGraphicsItemGroup* itemGroup;
};
To copy to clipboard, switch view to plain text mode
MainGui.cpp
#include "container.h"
Container*c1= new Container (0,0,0);
Container*c2= new Container (0,0,0);
scene= new Scene(this);
itemGroup= scene->createItemGroup(scene->selectedItems());
c1->advance();
itemGroup->addToGroup(c1);
c1-> setZValue(405.0);/*I'm trying to separate the RectItems so that their do not overlap because i want them to be range in a queue. into the scene.*/
c2->advance();
itemGroup->addToGroup(c2);
c2-> setZValue(400.0);
#include "container.h"
Container*c1= new Container (0,0,0);
Container*c2= new Container (0,0,0);
scene= new Scene(this);
itemGroup= scene->createItemGroup(scene->selectedItems());
c1->advance();
itemGroup->addToGroup(c1);
c1-> setZValue(405.0);/*I'm trying to separate the RectItems so that their do not overlap because i want them to be range in a queue. into the scene.*/
c2->advance();
itemGroup->addToGroup(c2);
c2-> setZValue(400.0);
To copy to clipboard, switch view to plain text mode
Bookmarks