#include <QtGui>
#include <QPropertyAnimation>
#include <QDebug>
 
  Q_OBJECT
  Q_PROPERTY(QPointF pos READ pos WRITE setPos
) public:
    setPen(pen);
    setBrush(brush);
  }
};
 
#include "main.moc"
 
int main(int argc, char **argv){
  view.setAttribute(Qt::WA_TranslucentBackground);
  view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
  view.setScene(&scene);
  RectItem 
*rect 
= new RectItem
(QRectF(0,
0,
200,
100), 
QPen(QColor(255,
0,
0,
0)),
QColor(0,
0,
255,
127) );   
//Qt::red  Qt::blue  scene.addItem(rect);
   //rect->setOpacity(0.5);
  //rect->setZValue(9);
  RectItem 
*rect1 
= new RectItem
(QRectF(0,
0,
200,
100), 
QPen(QColor(255,
0,
0,
0)),
QColor(255,
0,
0,
255) );   
//Qt::red  Qt::blue  scene.addItem(rect1);
  QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
  anim->setDuration(50000);
  anim->setStartValue(scene.sceneRect().topLeft());
  anim->setEndValue(scene.sceneRect().bottomRight());
  anim->start();
  QPropertyAnimation *anim1 = new QPropertyAnimation(rect1, "pos");
  anim1->setDuration(50000);
  anim1->setStartValue(scene.sceneRect().topRight());
  anim1->setEndValue(scene.sceneRect().bottomLeft());
  anim1->start();
 
  qDebug()  << "In Code \n" ;
  view.show();
  return app.exec();
}
        #include <QtGui>
#include <QPropertyAnimation>
#include <QDebug>
class RectItem : public QObject, public QGraphicsRectItem {
  Q_OBJECT
  Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
  RectItem(const QRectF &rect, const QPen &pen, const QBrush &brush) : QObject(), QGraphicsRectItem(rect){
    setPen(pen);
    setBrush(brush);
  }
};
#include "main.moc"
int main(int argc, char **argv){
  QApplication app(argc, argv);
  QGraphicsView view;
  view.setAttribute(Qt::WA_TranslucentBackground);
  view.viewport()->setAttribute(Qt::WA_TranslucentBackground);
  QGraphicsScene scene(QRectF(0,0,1000,800));
  view.setScene(&scene);
  RectItem *rect = new RectItem(QRectF(0,0,200,100), QPen(QColor(255,0,0,0)),QColor(0,0,255,127) );   //Qt::red  Qt::blue
  scene.addItem(rect);
   //rect->setOpacity(0.5);
  //rect->setZValue(9);
  RectItem *rect1 = new RectItem(QRectF(0,0,200,100), QPen(QColor(255,0,0,0)),QColor(255,0,0,255) );   //Qt::red  Qt::blue
  scene.addItem(rect1);
  QPropertyAnimation *anim = new QPropertyAnimation(rect, "pos");
  anim->setDuration(50000);
  anim->setStartValue(scene.sceneRect().topLeft());
  anim->setEndValue(scene.sceneRect().bottomRight());
  anim->start();
  QPropertyAnimation *anim1 = new QPropertyAnimation(rect1, "pos");
  anim1->setDuration(50000);
  anim1->setStartValue(scene.sceneRect().topRight());
  anim1->setEndValue(scene.sceneRect().bottomLeft());
  anim1->start();
  qDebug()  << "In Code \n" ;
  view.show();
  return app.exec();
}
To copy to clipboard, switch view to plain text mode 
  
				
Bookmarks