1
グラフィックビューフレームワークを使用してQt:DotLine
ペンで描画された回転円を作成したいと思います。 QGraphicsItemAnimation
を使用すると、他の図形は回転できますが、円は回転できません。以下のプログラムは問題を示しています:四角形と円が一緒に回転するのではなく、四角形が優雅に回転している間に円が動きます。点線ペン付きアニメーションQGraphicsItem
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QTimeLine>
#include <QGraphicsItemAnimation>
QRectF rect (int r)
{
return QRectF (-r, -r, r * 2, r * 2);
}
void setupRot (QTimeLine *timeline, QGraphicsItem *item)
{
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
animation->setItem(item);
animation->setTimeLine(timeline);
animation->setRotationAt (1, 360);
QObject::connect (timeline, SIGNAL(finished()), animation, SLOT(deleteLater()));
}
int main(int argc, char *argv[])
{
QApplication app (argc, argv);
QGraphicsScene scene;
QTimeLine *timeline = new QTimeLine;
timeline->setDuration (3000);
timeline->setCurveShape (QTimeLine::LinearCurve);
QObject::connect (timeline, SIGNAL(finished()), timeline, SLOT(deleteLater()));
setupRot (timeline, scene.addEllipse (rect (50), QPen (QBrush (QColor ("blue")), 8, Qt::DotLine)));
setupRot (timeline, scene.addRect (rect (60)));
scene.addEllipse (rect (40), QPen (QBrush (QColor ("red")), 8));
scene.setSceneRect (-100, -100, 200, 200);
QGraphicsView view (&scene);
view.show();
timeline->setLoopCount (0);
timeline->start();
return app.exec();
}
PS:私はこのように、人々は手動で中間アニメーション手順を作成しているウェブ上のいくつかのサンプルコードを見つけた:
const int steps = 100;
for (int i = 0; i < steps; ++i)
animation->setRotationAt (i/(float)steps, 360/(float)steps * i);
は、これは人々の単なる兆候であります補間の概念を理解していない、または(一見余分な)制御点を設定することの利点がいくつかありますか?
これはQT 4.7.0のLinux/X11上にあります。 – Cactus