Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:59:14+00:00 2026-06-17T09:59:14+00:00

I’m trying to find a way to do a transition on a QML element,

  • 0

I’m trying to find a way to do a transition on a QML element, when a binding changes. Say you have a Text element, with the text property bound to something. What I want is when the data in the binding changes, the element fades out (Still displaying old data), switches and fades back in with the new data (the actual transition occurring while the element isn’t visible.)

I’ve been searching everywhere for a way to do this but I can figure it out. I’ve tried using Qt Quick animations within QML, but the data itself changes before the animation runs, leaving the animation unnecessary. I’ve tried creating a custom QDeclarativeItem object that calls an animation within the QDeclarativeItem::paint() but I can’t figure out how to get it to actually run.

I should note here that I know my bindings are working fine as the displayed data changes, I just can’t get these animations to run at the proper time.

Here is what I tried with QML:

Text {
    id: focusText
    text: somedata

    Behavior on text {
         SequentialAnimation {
             NumberAnimation { target: focusText; property: "opacity"; to: 0; duration: 500 }
             NumberAnimation { target: focusText; property: "opacity"; to: 1; duration: 500 }
         }
     }
}

And here is what I tried in implementing a custom QDeclarativeItem:

// PAINTER
void AnimatedBinding::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    // Setup the pen
    QPen pen(m_color, 2);
    painter->setPen(pen);
    painter->setOpacity(this->opacity());

    // Draw the item
    if (m_bindingType == QString("text")) {
        QPropertyAnimation animation(this, "opacity");
        animation.setDuration(1000);
        animation.setStartValue(1);

        if (drawn) {
            animation.setStartValue(1);
            animation.setEndValue(0);
            animation.start();
        } else drawn = true;

        painter->drawText(boundingRect(), m_data.toString());
        animation.setEndValue(0);
        animation.start();
    } else {
        qCritical() << "Error unknown binding type!";
        return;
    }
}

But like I said, the animation that I start within the painter never actually fires.

Any tips? Anyone ever done this before? I’ve been banging my head on this for about a week.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:59:16+00:00Added an answer on June 17, 2026 at 9:59 am

    How about doing it in qml only this ways :

    1. Define a custom element of your own type, that behaves the way you want it to.
    2. Use this element instead of traditional element to be animated.

    eg. I have create a custom ‘AnimatedText’ type to have the fading in and fading out behavior on the text elements whenever text related to them changes.

    File 1 : AnimatedText.qml

    import QtQuick 1.0
    
    Item
    {
        id: topParent
        property string aText: ""
        property string aTextColor: "black"
        property int aTextFontSize: 10
        property int aTextAnimationTime : 1000
    
        Behavior on opacity { NumberAnimation { duration: aTextAnimationTime } }
    
        onATextChanged:
        {
             topParent.opacity = 0
             junkTimer.running = true
        }
    
        Timer
        {
           id: junkTimer
           running: false
           repeat: false
           interval: aTextAnimationTime
           onTriggered:
           {
               junkText.text = aText
               topParent.opacity = 1
           }
        }
    
        Text
        {
            id: junkText
            anchors.centerIn: parent
            text: ""
            font.pixelSize: aTextFontSize
            color: aTextColor
        }
    }
    

    and in your main.qml

    import QtQuick 1.0
    
    Rectangle
    {
        id: topParent
        width:  360
        height: 360
    
        AnimatedText
        {
          id: someText
    
          anchors.centerIn: parent
          aText: "Click Me to change!!!.."
          aTextFontSize: 25
          aTextColor: "green"
          aTextAnimationTime: 500
        }
    
        MouseArea
        {
            anchors.fill: parent
            onClicked:
            {
                someText.aText = "Some random junk"
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.