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. Start animation with click on mouse area

Start animation with click on mouse area

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 532 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
    ChristianSky
    wrote on 17 Jul 2022, 11:55 last edited by
    #1

    Hello,
    I think I have a very simple problem, but I'm completely stumped right now.

    I have two files:
    App.qml
    Screen01.ui.qml

    In Screen01.ui.qml I have two text elements (freqzency1a & frequency1b) which I want to swap by an animation from left to right.
    I have already created an animation id: changeFrequency1 in Screen01.ui.qml.

    Additionally I have created a MouseArea in App.qml.

    Question:

    1. is the division into the two files so correct?
    2. how can I trigger the animation changeFrequency1 by clicking on the MouseArea?

    Thanks a lot
    Christian

    App.qml

    import QtQuick
    import QtQuick.Window
    import Communication2
    import QtQuick.Timeline 1.0
    
    Window {
        width: mainScreen.width
        height: mainScreen.height
    
        visible: true
        title: "Communication2"
    
        Screen01 {
            id: mainScreen
        }
    
    
        Text {
            id: change1
            x: 180
            y: 115
            color: "#1b9993"
            text: qsTr("< >")
            font.pixelSize: 16
    
            MouseArea {
                id: change1MouseArea
                x: -10
                y: 0
                width: 46
                height: 26
                hoverEnabled: true
                cursorShape: Qt.SizeHorCursor
            }
        }
    
    }
    

    Screen01.ui.qml

    import QtQuick
    import QtQuick.Controls
    import Communication2
    import QtQuick.Studio.Components 1.0
    
    import QtQuick.Timeline 1.0
    
    Rectangle {
        //Item {
        id: root
    
        width: Constants.width
        height: Constants.height
        color: Constants.backgroundColor
    
        property string freq1a: "bla1"
        property string freq1b: "bla2"
    
        Text {
            id: frequency1a
            x: 90
            y: 115
            width: 65
            color: "#ffffff"
            text: root.freq1a
            font.pixelSize: 16
        }
    
        Text {
            id: frequency1b
            x: 275
            y: 115
            width: 65
            color: "#908a8a"
            text: root.freq1b
            font.pixelSize: 16
        }
    
        //Beginn of the timeline
        Timeline {
            id: changeFrequency1
            animations: [
                TimelineAnimation {
                    id: timelineAnimation
                    loops: 1
                    duration: 1000
                    running: false
                    to: 1000
                    from: 0
                }
            ]
            startFrame: 0
            endFrame: 1000
            enabled: true
    
            KeyframeGroup {
                target: frequency1a
                property: "x"
                Keyframe {
                    value: 90
                    frame: 0
                }
    
                Keyframe {
                    value: 275
                    frame: 1000
                }
            }
    
            KeyframeGroup {
                target: frequency1b
                property: "x"
                Keyframe {
                    value: 275
                    frame: 0
                }
    
                Keyframe {
                    value: 90
                    frame: 1000
                }
            }
        }
    }
    
    
    
    
    1 Reply Last reply
    0
    • S sierdzio
      18 Jul 2022, 04:48

      id is not visiblew outside a file. So to make it possible to access your animation outside, export it as a property, for example:

      // Screen01
      Rectangle {
        property alias swapAnimation: changeFrequency1
        id: root
      

      And now in main.qml:

      MouseArea {
        id: change1MouseArea
        onClicked: mainScreen.swapAnimation.start()
      
      C Offline
      C Offline
      ChristianSky
      wrote on 18 Jul 2022, 20:19 last edited by
      #3

      @sierdzio please correct me if I am wrong, but could it be that I need:

      property alias swapAnimation: timelineAnimation
      
      

      instead of

       property alias swapAnimation: changeFrequency1
      

      Thank you

      Christian

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 18 Jul 2022, 04:48 last edited by
        #2

        id is not visiblew outside a file. So to make it possible to access your animation outside, export it as a property, for example:

        // Screen01
        Rectangle {
          property alias swapAnimation: changeFrequency1
          id: root
        

        And now in main.qml:

        MouseArea {
          id: change1MouseArea
          onClicked: mainScreen.swapAnimation.start()
        

        (Z(:^

        C 1 Reply Last reply 18 Jul 2022, 20:19
        0
        • S sierdzio
          18 Jul 2022, 04:48

          id is not visiblew outside a file. So to make it possible to access your animation outside, export it as a property, for example:

          // Screen01
          Rectangle {
            property alias swapAnimation: changeFrequency1
            id: root
          

          And now in main.qml:

          MouseArea {
            id: change1MouseArea
            onClicked: mainScreen.swapAnimation.start()
          
          C Offline
          C Offline
          ChristianSky
          wrote on 18 Jul 2022, 20:19 last edited by
          #3

          @sierdzio please correct me if I am wrong, but could it be that I need:

          property alias swapAnimation: timelineAnimation
          
          

          instead of

           property alias swapAnimation: changeFrequency1
          

          Thank you

          Christian

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 19 Jul 2022, 05:37 last edited by
            #4

            Most probably, yes.

            (Z(:^

            1 Reply Last reply
            0

            3/4

            18 Jul 2022, 20:19

            • Login

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