Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 18th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Scaling in QGraphicsItemAnimation
  2. timeline = new QTimeLine(time);
  3.     timeline->setFrameRange(0, 100);
  4.     animation = new QGraphicsItemAnimation;
  5.  
  6.     QRectF rect = item->boundingRect();
  7.     int h = rect.bottom() - rect.top();
  8.     int w = rect.right() - rect.left();
  9.  
  10.  
  11.     animation->setItem(item);
  12.     animation->setTimeLine(timeline);
  13.  
  14.  
  15.     for (int i = 0; i < 100; i++) {
  16.             int x = w + (int)((float)w*(float)(i/100.0));
  17.             qreal xx = (qreal)(x)/(qreal)w;
  18.             int y = (h) + (int)((float)h*(float)(i/100.0));
  19.             qreal yy = (qreal)(y)/(qreal)h;          
  20.             animation->setScaleAt(i/100, xx, yy);
  21.     }
  22.        
  23. const QSizeF size = item->boundingRect().size()*0.5;
  24. item->setOffset(size.width(), size.height());
  25. item->moveBy(size.width(), size.height());