Bonjour à tous,
Je souhaiterais animer un QGraphicsProxyWidget, en lui appliquant une rotation, pas autour de l'axe z comme le fait la fonction setRotation(), mais autour de l'axe y.
Ceci se fait habituellement avec la fonction setTransform(), cependant il n'existe pas apparemment de propriété 'transform' ou 'transformation' à passer au QPropertyAnimation. J'ai donc créé une classe "cover" héritant de QGraphicsProxyWidget pour rajouter cette propriété :
cover.h :
cover.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifndef COVER_H #define COVER_H #include <QtGui> class cover : public QGraphicsProxyWidget { Q_OBJECT Q_PROPERTY(QTransform transform READ transform WRITE setT) public: cover(); ~cover(); void setT(QTransform t); }; #endif // COVER_H
J'ai donc essayé d'animer cette propriété comme n'importe quelle autre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include "cover.h" cover::cover() : QGraphicsProxyWidget() { } cover::~cover() { } void cover::setT(QTransform t){ this->setTransform(t); }
Mais rien ne se produit... J'ai essayé de mettre en breakpoint sur la méthode setT() de cover, mais elle ne semble pas être appelée...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <QtGui> #include "cover.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QPushButton *button = new QPushButton("Bonjour"); QGraphicsScene scene; scene.setSceneRect(0 , 0, 100, 100); cover *proxy = new cover(); proxy->setWidget(button); scene.addItem(proxy); QTransform matrix; matrix.translate(25,25); QTransform matrixa; matrixa.translate(25,25); matrixa.rotate(45, Qt::YAxis); QGraphicsView view(&scene); view.show(); QPropertyAnimation animation(proxy, "transform"); animation.setDuration(3000); animation.setStartValue(matrix); animation.setEndValue(matrixa); animation.setEasingCurve(QEasingCurve::OutBounce); animation.start(); view.setWindowTitle("Ma première scène"); return a.exec(); }
Comment faut-il s'y prendre pour animer le QGraphicsProxyWidget ?
Merci d'avance pour vos réponses
A+
Partager