IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Discussion :

Déplacement d'image : dissocier les axes X et Y

  1. #1
    Invité
    Invité(e)
    Par défaut Déplacement d'image : dissocier les axes X et Y
    Bonjour,

    J'utilise Qt depuis peu et je sèche sur un problème (jusqu'à présent j'ai pu m'en sortir grâce à la doc vraiment bien faite). Je n'arrive pas à utiliser setEasingCurve comme je le voudrais et à vrai dire, je ne sais même pas si c'est cette fonction qu'il me faut.

    Mon problème :
    Je cherche à déplacer une image (que j'ai collé dans un QLabel).
    La vitesse de déplacement sur l'axe x doit être constante tandis que celle sur l'axe y doit être variable.

    Ici, le "setEasingCurve(QEasingCurve::InOutSine);" applique une variation de vitesse identique sur les deux axes. Je n'arrive pas à dissocier les deux axes.

    Voilà le bout de code concerné :
    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
            QDialog *anim = new QDialog;
            anim->setWindowTitle("OK");
            anim->setFixedSize(800,600);
     
            QLabel *diab = new QLabel();
            diab->setPixmap(QPixmap("images/diabolo.png"));
     
            QPropertyAnimation *animation = new QPropertyAnimation(diab, "geometry");
            animation->setDuration(3000);
     
            // trajet en l'air
            animation->setKeyValueAt(0,QRect(330, 350, 67, 67));
            animation->setKeyValueAt(0.5,QRect(250, 50, 67, 67));
            animation->setKeyValueAt(1,QRect(170, 350, 67, 67));
     
            animation->setEasingCurve(QEasingCurve::InOutSine);
     
            animation->setLoopCount(-1);
     
            animation->start();
     
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(diab);
            anim->setLayout(layout);
            anim->show();
    Si quelqu'un a une idée. Là, je ne vois vraiment pas...

    Merci d'avance
    Dernière modification par Invité ; 02/02/2012 à 09h27.

  2. #2
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2009
    Messages
    1 009
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2009
    Messages : 1 009
    Points : 1 738
    Points
    1 738
    Par défaut
    Là tu animes le QRect (ce qui me semble compliqué à contrôler). Tu définis différentes étapes, mais une animation unique entre ces étapes.

    Ce qu'il te faut, c'est utiliser une animation pour x et une pour y. Ensuite une classe pratique : QParallelAnimationGroup, pour exécuter deux animations simultanément.

    Là du coup tu pourras définir pour chaque animation une "EasingCurve" distincte.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonjour et merci pour cette réponse.

    Je ne connaissait pas QParallelAnimationGroup . Ça me sera aussi utile par la suite.

    Voilà ce que j'ai essayé :
    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
    39
     
            QDialog *anim = new QDialog;
            anim->setWindowTitle("OK");
            anim->setFixedSize(800,600);
     
            QLabel *diab = new QLabel();
            //diab->move(330,500);
            diab->setPixmap(QPixmap("images/diabolo.png"));
     
            QParallelAnimationGroup* animationXY = new QParallelAnimationGroup;
     
            QPropertyAnimation *animX = new QPropertyAnimation(diab, "x"); //
            animX->setDuration(1000);
            //animX->setStartValue(330);
            animX->setKeyValueAt(0,330);
            animX->setKeyValueAt(0.5,100);
            animX->setKeyValueAt(1,330);
            //animX->setEndValue(330);
            animX->setLoopCount(-1);
            animationXY->addAnimation(animX);
     
            QPropertyAnimation *animY = new QPropertyAnimation(diab, "y");
            animY->setDuration(1000);
           // animY->setStartValue(330);
            animY->setKeyValueAt(0,330);
            animY->setKeyValueAt(0.5,100);
            animY->setKeyValueAt(1,330);
            //animY->setEndValue(330);
            animY->setEasingCurve(QEasingCurve::InOutSine);
            animY->setLoopCount(-1);
            animationXY->addAnimation(animY);
     
            animationXY->start();
     
     
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(diab);
            anim->setLayout(layout);
            anim->show();
    La compilation se passe bien mais lors de l'exécution, ça me renvoi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    QPropertyAnimation: you're trying to animate the non-writable property x of your QObject
    QPropertyAnimation: you're trying to animate the non-writable property y of your QObject
    QPropertyAnimation: you're trying to animate the non-writable property x of your QObject
    QPropertyAnimation: you're trying to animate the non-writable property y of your QObject
    (mon image s'affiche mais pas de déplacement)

    Si je comprend bien, les propriétés x et y de mon QLabel existent (trouvé dans la doc) mais je ne peux pas les modifier comme ça.

    [edit] j'ai compris pourquoi j'ai ce message : je n'ai pas de setter mais seulement un getter pour ces deux propriétés. Mon problème reste entier...
    Dernière modification par Invité ; 01/02/2012 à 11h37.

  4. #4
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2009
    Messages
    1 009
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2009
    Messages : 1 009
    Points : 1 738
    Points
    1 738
    Par défaut
    Exact, ce sont des propriétés "const"... Je pense que tu peux t'en sortir avec la propriété "pos" (setter : move()) :

    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
    39
     
            QDialog *anim = new QDialog;
            anim->setWindowTitle("OK");
            anim->setFixedSize(800,600);
     
            QLabel *diab = new QLabel();
            //diab->move(330,500);
            diab->setPixmap(QPixmap("images/diabolo.png"));
     
            QParallelAnimationGroup* animationXY = new QParallelAnimationGroup;
     
            QPropertyAnimation *animX = new QPropertyAnimation(diab, "pos"); //
            animX->setDuration(1000);
            //animX->setStartValue(QPoint(330, diab->y()));
            animX->setKeyValueAt(0,QPoint(330, diab->y()));
            animX->setKeyValueAt(0.5,QPoint(100, diab->y()));
            animX->setKeyValueAt(1,QPoint(330, diab->y()));
            //animX->setEndValue(QPoint(330, diab->y()));
            animX->setLoopCount(-1);
            animationXY->addAnimation(animX);
     
            QPropertyAnimation *animY = new QPropertyAnimation(diab, "pos");
            animY->setDuration(1000);
           // animY->setStartValue(QPoint(diab->x(), 330));
            animY->setKeyValueAt(0,QPoint(diab->x(), 330));
            animY->setKeyValueAt(0.5,QPoint(diab->x(), 100));
            animY->setKeyValueAt(1,QPoint(diab->x(), 330));
            //animY->setEndValue(QPoint(diab->x(), 330));
            animY->setEasingCurve(QEasingCurve::InOutSine);
            animY->setLoopCount(-1);
            animationXY->addAnimation(animY);
     
            animationXY->start();
     
     
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(diab);
            anim->setLayout(layout);
            anim->show();
    J'ai tapé le code à la main ici, il y a peut-être des erreurs mais tu vois le principe ? Je ne suis pas sûr que ça marche par contre.

  5. #5
    Invité
    Invité(e)
    Par défaut
    Malheureusement cela ne fonctionne pas mieux (image affichée mais reste figée). Que cela soit avec un QRect ou un QPoint, on manipule toujours x et y en même temps.

    Je vais essayer de trouver un autre moyen pour arriver à mes fins. Il y a peut être d'autres fonctions plus adaptées.


    En tout cas, merci.

  6. #6
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2009
    Messages
    1 009
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2009
    Messages : 1 009
    Points : 1 738
    Points
    1 738
    Par défaut
    J'ai essayé quelque chose qui fonctionne :

    .h
    Code C++ : 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
    #ifndef QMOVABLELABEL_H
    #define QMOVABLELABEL_H
     
    #include <QLabel>
     
    class QMovableLabel : public QLabel
    {
        Q_OBJECT
        Q_PROPERTY(int posX READ posX WRITE setPosX)
        Q_PROPERTY(int posY READ posY WRITE setPosY)
     
    public:
        explicit QMovableLabel(QWidget *parent = 0);
     
        int posX() const;
        void setPosX(int);
     
        int posY() const;
        void setPosY(int);
    };
     
    #endif // QMOVABLELABEL_H

    .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
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #include "qmovablelabel.h"
     
    QMovableLabel::QMovableLabel(QWidget *parent) :
        QLabel(parent)
    {
    }
     
    int QMovableLabel::posX() const
    {
        return x();
    }
     
    void QMovableLabel::setPosX(int i)
    {
        move ( i, y() );
    }
     
    int QMovableLabel::posY() const
    {
        return y();
    }
     
    void QMovableLabel::setPosY(int j)
    {
        move ( x(), j );
    }
    Et pour l'animation, tu utilises les propriétés posX et posY qui sont "settables" cette fois . Ça marche même sans "READ", bien que qmake signale que ce n'est pas possible... bizarre.

  7. #7
    Invité
    Invité(e)
    Par défaut
    Merci beaucoup, ça fonctionne nickel et j'ai appris des choses en plus.

    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
     
            QDialog *anim = new QDialog;
            anim->setWindowTitle("OK");
            anim->setFixedSize(800,600);
     
            QMovableLabel *diab = new QMovableLabel();
            diab->setPixmap(QPixmap("images/diabolo.png"));
     
            QParallelAnimationGroup* animationXY = new QParallelAnimationGroup;
     
            QPropertyAnimation *animX = new QPropertyAnimation(diab, "posX");
            animX->setDuration(4000);
            animX->setKeyValueAt(0,50);
            animX->setKeyValueAt(0.5,700);
            animX->setKeyValueAt(1,50);
            animX->setLoopCount(-1);
            animationXY->addAnimation(animX);
     
            QPropertyAnimation *animY = new QPropertyAnimation(diab, "posY");
            animY->setDuration(2000);
            animY->setKeyValueAt(0, 200);
            animY->setKeyValueAt(0.5, -200);
            animY->setKeyValueAt(1,200);
            animY->setLoopCount(-1);
            animY->setEasingCurve(QEasingCurve::OutInSine);
            animationXY->addAnimation(animY);
     
            animationXY->start();
     
     
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(diab);
            anim->setLayout(layout);
            anim->show();

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. afficher image jpg sans les axes gradués
    Par Thib0ult dans le forum Interfaces Graphiques
    Réponses: 2
    Dernier message: 06/05/2015, 14h21
  2. [WD-2007] Déplacement images avec les flèches impossible
    Par riko31 dans le forum Word
    Réponses: 3
    Dernier message: 25/12/2013, 14h35
  3. [Matplotlib] Insérer des images sur les axes
    Par mOoler dans le forum Calcul scientifique
    Réponses: 0
    Dernier message: 13/06/2011, 10h20
  4. Ajusté les Axes d'un graphe en fonction des données rentrée!
    Par Ma2thieu dans le forum Composants VCL
    Réponses: 5
    Dernier message: 09/07/2004, 01h34
  5. faire un selection dans une image aves les APIs
    Par merahyazid dans le forum C++Builder
    Réponses: 3
    Dernier message: 30/04/2002, 10h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo