I want to make an animation with two circlewidget in a scene. My purpose is to make the first widget with concentric circle animated for a periode of time and then stop it, after make the second widget animated also for a periode of time .
but I get blocked how to make such thing here is my code:
Main.cpp:
#include <QApplication>
#include <QTimer>
#include<unistd.h>
#include<QGraphicsScene>
#include<QGraphicsProxyWidget>
#include<QGraphicsView>
#include "circlewidget.h"
#include<QTimeLine>
int main(int argc, char *argv[])
{
CircleWidget * circle= new CircleWidget();
CircleWidget * circl= new CircleWidget();
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
proxy->setWidget(circle);
proxy->setPos(0,1);
scene.addItem(proxy);
QGraphicsProxyWidget *prox = new QGraphicsProxyWidget();
prox->setWidget(circl);
prox->setPos(200,100);
scene.addItem(prox);
/*QTimeLine *timer = new QTimeLine(5000);
timer->setFrameRange(0, 100);*/
QObject::connect(timer,
SIGNAL(timeout
()), circl,
SLOT(nextAnimationFrame
()));
timer->start();
sleep(5);
timer->stop();
QObject::connect(time,
SIGNAL(timeout
()),circle,
SLOT(nextAnimationFrame
()));
time->start();
view.show();
return app.exec();
}
#include <QApplication>
#include <QTimer>
#include<unistd.h>
#include<QGraphicsScene>
#include<QGraphicsProxyWidget>
#include<QGraphicsView>
#include "circlewidget.h"
#include<QTimeLine>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CircleWidget * circle= new CircleWidget();
CircleWidget * circl= new CircleWidget();
QGraphicsScene scene;
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget();
proxy->setWidget(circle);
proxy->setPos(0,1);
scene.addItem(proxy);
QTimer * time=new QTimer();
QTimer * timer=new QTimer();
QGraphicsProxyWidget *prox = new QGraphicsProxyWidget();
prox->setWidget(circl);
prox->setPos(200,100);
scene.addItem(prox);
/*QTimeLine *timer = new QTimeLine(5000);
timer->setFrameRange(0, 100);*/
QGraphicsView view(&scene);
QObject::connect(timer, SIGNAL(timeout()), circl, SLOT(nextAnimationFrame()));
timer->start();
sleep(5);
timer->stop();
QObject::connect(time, SIGNAL(timeout()),circle, SLOT(nextAnimationFrame()));
time->start();
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
circlewidget.cpp:
#include <QtGui>
#include "circlewidget.h"
#include<unistd.h>
#include <stdlib.h>
CircleWidget
::CircleWidget(QWidget *parent
) {
}
QSize CircleWidget
::minimumSizeHint() const {
}
QSize CircleWidget
::sizeHint() const {
}
void CircleWidget::nextAnimationFrame()
{
update();
++ frameNo;
}
{
painter.
setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
for (int diameter = 0; diameter < 170; diameter += 6) {
int delta = abs((frameNo %120) - diameter / 2);
int alpha = 250 - (delta * delta) / 3 - diameter;
if (alpha > 0) {
painter.
setPen(QPen(QColor(166, diameter
/ 2,
32, alpha
),
5));
painter.
drawEllipse(QRectF(-diameter
/ 2.0,
-diameter
/ 2.0,
diameter, diameter));
}
}
}
#include <QtGui>
#include "circlewidget.h"
#include<unistd.h>
#include <stdlib.h>
CircleWidget::CircleWidget(QWidget *parent)
: QWidget(parent)
{
setBackgroundRole(QPalette::Base);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
QSize CircleWidget::minimumSizeHint() const
{
return QSize(50, 50);
}
QSize CircleWidget::sizeHint() const
{
return QSize(180, 180);
}
void CircleWidget::nextAnimationFrame()
{
update();
++ frameNo;
}
void CircleWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
for (int diameter = 0; diameter < 170; diameter += 6) {
int delta = abs((frameNo %120) - diameter / 2);
int alpha = 250 - (delta * delta) / 3 - diameter;
if (alpha > 0) {
painter.setPen(QPen(QColor(166, diameter / 2, 32, alpha), 5));
painter.drawEllipse(QRectF(-diameter / 2.0, -diameter / 2.0,
diameter, diameter));
}
}
}
To copy to clipboard, switch view to plain text mode
ciclewidget.h:
#ifndef CIRCLEWIDGET_H
#define CIRCLEWIDGET_H
#include <QWidget>
class CircleWidget
: public QWidget {
Q_OBJECT
public:
QSize minimumSizeHint
() const;
public slots:
void nextAnimationFrame();
protected:
private:
int frameNo;
};
#endif
#ifndef CIRCLEWIDGET_H
#define CIRCLEWIDGET_H
#include <QWidget>
class CircleWidget : public QWidget
{
Q_OBJECT
public:
CircleWidget(QWidget *parent = 0);
QSize minimumSizeHint() const;
QSize sizeHint() const;
public slots:
void nextAnimationFrame();
protected:
void paintEvent(QPaintEvent *event);
private:
int frameNo;
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks