qte2::qte2(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ ui.setupUi(this); scene=new mainscene(); connect(ui.pushButton, SIGNAL(clicked()), SLOT(ButtonCl())); ui.graphicsView->setScene(scene); ui.graphicsView->setSceneRect(QRectF(3,5,7,7)) ; }void qte2::ButtonCl( void ) { liniya=scene->addLine(1,1,20,20); scene->addLine(100,100,120,120); }
QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20); QTimeLine *timer = new QTimeLine(5000); timer->setFrameRange(0, 100); QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; animation->setItem(ball); animation->setTimeLine(timer); for (int i = 0; i < 200; ++i) animation->setPosAt(i / 200.0, QPointF(i, i)); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 250, 250); scene->addItem(ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); timer->start();