I am trying to find a way to make a transition on a QML element when the binding changes. Say you have a Text element, with a Text attribute associated with something. What I want is when the data in the binding changes, the element disappears (the old data is still displayed), it switches and disappears with the new data (the actual transition occurs until the element is displayed.)
I searched everywhere to do this, but I can figure it out. I tried using Qt Quick animations in QML, but the data itself changes before the animation starts, leaving the animation unnecessary. I tried to create a custom QDeclarativeItem object that calls the animation in QDeclarativeItem::paint() , but I cannot figure out how to start it.
I should note here that I know that my bindings work fine, as the displayed data changes, I just can't get these animations to work at the right 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 when 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, as I said, the animation that I start inside the artist never works.
Any tips? Has anyone ever done this before? I punched my head for about a week.