I'm trying to animate a line around a fixed point in Qt. I assume I need to use the QPropertyAnimation class to do this but cannot figure out which property to use.
For clarity, here's what I'm trying to do.
| (5, 10)
| /
| /
| /
| / (10, 5)
| / .
| /
| /
|/
|--------------------------
^
|---(0,0)
Given (x1, y1) = (0, 0) & (x2, y2) = (5, 10), this would be the first frame of the animation. I'd like to then do a smooth animation from (x1, y1), (x2, y2), (with (x1, y1) being one end of the line and (x2, y2) being the other end) to (x1, y1), (x3, y3), with (x3, y3) = (10, 5). Similar to how a clock hand is animated. And before someone posts the analog clock example it uses a rotating pixmap which is not what I need.
I haven't found a whole lot of information on Qt animations, just a lot of basic GUI tutorials.
I have tried doing the following
QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry")
and the problem with this method is that in this technique the widget is moved between 2 points based on (0, 0) of the widget using the ->setStartValue(startX, startY, ...) and does not allow me to keep one of my lines at a fixed point.
and
QPropertyAnimation *anim = new QPropertyAnimation(widget, "rotation")
The problem with this method being similar to geometry in that it rotates said widget along a (0, 0) point.
Can someone tell me how to achieve the desired effect?
Thanks.
QGraphicsXXXItemdo not support q-properties so they can not be used withQPropertyAnimationdirectly. So the solution is to create a class that inheritsQObjectandQGraphicsLineItem, plus we must add a q-property that handles thep2position of theQLineFassociated with the line as shown below:lineitem.h
main.cpp
Another way is to use QVariantAnimation: