Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to trigger a timeline created with Design Studio from C++?
QtWS25 Last Chance

How to trigger a timeline created with Design Studio from C++?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
timelinec++
1 Posts 1 Posters 243 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coldspark29
    wrote on 29 Aug 2021, 13:22 last edited by coldspark29
    #1

    I have created simple timeline in Design Studio, which scales an image up and down. I now want to trigger the start from C++.

    Here is my QML code

        Timeline {
            id: timeline
            animations: [
                TimelineAnimation {
                    id: timelineAnimation
                    duration: 1000
                    loops: 0
                    running: true
                    to: 1000
                    from: 0
                }
            ]
            endFrame: 1000
            startFrame: 0
            enabled: true
    
            KeyframeGroup {
                target: image
                property: "scale"
                Keyframe {
                    value: 1.25
                    frame: 100
                }
    
                Keyframe {
                    value: 1
                    frame: 1000
                }
            }
    

    I have found this documenation

    https://doc.qt.io/qt-5/qtimeline.html

    and from what I understand I first have to expose the scale property, which is then triggered by the timeline which is created in C++.. I have written this function.

    #include <QObject>
    #include <QTimeLine>
    #include <qqml.h>
    
    class Scaler: public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QVariant scale WRITE setScale NOTIFY scaleSet)
        QML_ELEMENT
        QVariant m_scale;
    
    public:
        explicit Scaler(QObject *parent = nullptr);
    
        void setScale(QVariant scale);
    
    signals:
        void scaleChanged(QVariant scale);
    
    };
    
    #include "Scaler.h"
    
    Scaler::Scaler(QObject *parent) :
        QObject(parent)
    {
    }
    
    
    void Scaler::setScale(QVariant scale)
    {
        if (m_scale == scale)
            return;
        m_scale = scale;
        emit scaleChanged(m_scale);
    }
    
    

    Now I want to use the timeline from the example

       Scaler scaler;
    
        QTimeLine *timeLine = new QTimeLine(1000, engine.rootContext());
        timeLine->setFrameRange(0, 100);
        connect(timeLine, &QTimeLine::frameChanged, scaler, &Scaler::setScale(1.25))
    

    but I am not sure how to use the connect function. I want the cale to go from 1 to 1.25 betwenn 0 and 100 ms and back to 1 from 100 to 1000.

    1 Reply Last reply
    0

    1/1

    29 Aug 2021, 13:22

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved