Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › How to change Behaviour on inherited sub-components

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8610

    Martin

    I have a Platform baseclass like this:

    EntityBase {
        property alias platformImage: platformImage
    
        entityType: "platform"
    
        width: 100
        height: 15
    
        Rectangle {
            id: platformImage
            anchors.fill: parent
            color: "white"
    
            Behavior on opacity {
                NumberAnimation {property: "opacity"; duration: 3000; easing.type: Easing.InQuart}
            }
        }
    

    However, the Behaviour on opacity really only belongs to a particular subclass of Platform.

    And I can imagine that I might want other behaviours for other subclasses.

    How can I create a subclass with different behaviour, something like this:

    Platform {
        platformImage.color: "red"
        platformImage.Behaviour on opacity {...}
    }
    

     

    (Note that the over-riding of the platformImage.color works the way I need, which is good, just can’t see how to do the behaviour)

     

    • This topic was modified 9 years, 3 months ago by  GreenAsJade.
    • This topic was modified 9 years, 3 months ago by  GreenAsJade.
    #8642

    Christian
    Felgo Team

    Hi Martin,

    you have 2 options:

    1.) Create the properties that you want to expose and use these in your animations/behaviors.

    2.) Expose the whole animation with an alias.

    The 2nd option is less good, because you then expose internals of the implementation.

    Here is an example:

    EntityBase {
        id: platform
        property alias platformImage: platformImage
    
        // option1 - better, because you can change the internal implementation as you just expose the API
        property int animationDuration: 3000 //default value, can be changed by the outside
    
        // option 2 (less good, because you expose internal implementation details to the outside)
        property alias anim: platformImage.numberAnimation
    
        entityType: "platform"
    
        width: 100
        height: 15
    
        Rectangle {
            id: platformImage
            anchors.fill: parent
            color: "white"
    
            Behavior on opacity {
                NumberAnimation {
     id: numberAnimation
    property: "opacity"; duration: platform.animationDuration; easing.type: Easing.InQuart}
            }
        }
    }
    
    // then accessible like that:
    Platform {
      //option 1
      animationDuration: 4000
      
      //option 2
      anim.duration: 4000
    }

     

    Cheers, Chris

    #8685

    Martin

    Thanks for these examples – they are good options to have.

    I think my question was not quite asking what I wanted to ask precisely.

    Actually, I want to _add_ the behaviour in the subclass.   The baseclass has no reason to have “Behaviour on opacity”.   A later subclass may need Behaviour on width (as an example).

    Could I add this behaviour in the subclass?

    (That’s what the example not-correct code that I gave was trying to illustrate)

     

     

    #8687

    Alex
    Felgo Team

    Hi,

    the correct syntax is:

    Platform {
        platformImage.color: "red"
        Behaviour on platformImage.opacity {...}
    }

    Cheers,
    Alex

    #8689

    Martin

    That’s great, thanks!

    Before I had in the base class:

     

            Behavior on opacity {
                NumberAnimation {property: "opacity"; duration: 3000; easing.type: Easing.InQuart}

     

    I put this, instead, in the derived class:

     

            Behavior on platformImage.opacity {
                NumberAnimation {property: "platformImage.opacity"; duration: 3000; easing.type: Easing.InQuart}

     

    and it didn’t work.

    I simplified it to this:

     

            Behavior on platformImage.opacity {
                NumberAnimation { duration: 3000; easing.type: Easing.InQuart}

     

    and it does work.

     

    But I wonder: how would I refer to some other property of platformImage to animate, if I wanted?

    #8695

    Alex
    Felgo Team

    Hi Martin,

    If you are defining a Behavior on a property, you already defined the property that you want to animate, so it does not make sense to specify the “property” in the animation after.

    If you want to animate e.g. the width of that image then you would call:

     Behavior on platformImage.width{
                NumberAnimation { duration: 3000; easing.type: Easing.InQuart}
    }

    Or you just define an animation like this and start it instead of automatically running an animation on every property change like the Behavior does:

    NumberAnimation {
      id: widthAnimation
      target: platformImage
      property: "width";
      duration: 3000;
      easing.type: Easing.InQuart
    }

    And then use it like this:

    widthAnimation.to = 200
    widthAnimation.start()

    Cheers,
    Alex

    • This reply was modified 9 years, 3 months ago by  Alex.
Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded