{
handchanger = new QPropertyAnimation(this, "rotationAngle");
connect(handchanger, SIGNAL(finished()), this, SLOT(reanimate()));
handchanger->setDuration(20000);
handchanger->setStartValue(0);
handchanger->setEndValue(360);
handchanger->setEasingCurve(QEasingCurve::Linear);
setCacheMode(ItemCoordinateCache);
}
void MyHand::setRotationValue(qreal angle)
{
if(m_angle != angle)
{
m_angle = angle;
QPointF o
= boundingRect
().
bottomLeft();
QTransform t;
t.translate(o.x(), o.y());
t.rotate(m_angle, Qt::ZAxis);
t.translate(-o.x(), -o.y());
setTransform(t);
}
}
void MyHand::reanimate()
{
handchanger->start();
}
{
if(hand
->line
() == QLineF(0,
0,
0,
0)) {
hand
->setPen
(QPen(Qt
::black,
2));
hand->setLine(rect.width() / 2, rect.height() / 2, rect.width()/2, 0);
addItem(hand);
hand->start();
hand->setZValue(10);
back->setBrush(Qt::yellow);
back->setZValue(5);
addItem(back);
}
}
int main(int argc, char *argv[])
{
v.setScene(new radarcircle);
// v.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
v.setGeometry(0, 0, 700, 700);
v.setSceneRect(0,0 ,700,700);
v.show();
return a.exec();
}
MyHand::MyHand(QGraphicsItem *parent) :
QGraphicsLineItem(parent)
{
handchanger = new QPropertyAnimation(this, "rotationAngle");
connect(handchanger, SIGNAL(finished()), this, SLOT(reanimate()));
handchanger->setDuration(20000);
handchanger->setStartValue(0);
handchanger->setEndValue(360);
handchanger->setEasingCurve(QEasingCurve::Linear);
setCacheMode(ItemCoordinateCache);
}
void MyHand::setRotationValue(qreal angle)
{
if(m_angle != angle)
{
m_angle = angle;
QPointF o = boundingRect().bottomLeft();
QTransform t;
t.translate(o.x(), o.y());
t.rotate(m_angle, Qt::ZAxis);
t.translate(-o.x(), -o.y());
setTransform(t);
}
}
void MyHand::reanimate()
{
handchanger->start();
}
void handscene::drawBackground(QPainter *painter, const QRectF &rect)
{
if(hand->line() == QLineF(0,0,0,0))
{
hand->setPen(QPen(Qt::black, 2));
hand->setLine(rect.width() / 2, rect.height() / 2, rect.width()/2, 0);
addItem(hand);
hand->start();
hand->setZValue(10);
back = new QGraphicsEllipseItem(0,0,rect.width(), rect.height());
back->setBrush(Qt::yellow);
back->setZValue(5);
addItem(back);
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView v;
v.setScene(new radarcircle);
// v.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
v.setGeometry(0, 0, 700, 700);
v.setSceneRect(0,0 ,700,700);
v.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks