Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Do animation in QML on function call from C++



  • Hello,
    I'm pretty new to QML, maybe someone can help me with my issue:
    I have main Rectange with some Items:
    @
    Rectangle
    {
    id: main_rect
    width: 500
    height: 500

    function onLoggedIn()
    {
        btn_login.text = "Logged in!"
        //Start opacity animation??? 
    }
    

    ......
    }
    @

    After some work done with C++ engine I need to call onLoggedIn function which will set button(Item) text to "Logged in!" and make whole window slowly disappear.
    @QGraphicsObject * obj = this->rootObject();
    if(obj != NULL)
    {
    QVariant returnedValue;
    QMetaObject::invokeMethod(obj, "onLoggedIn",Q_RETURN_ARG(QVariant, returnedValue));
    }@

    The function gets called, text is set on the button, but how do I do this animation?
    Thank you in advance!



  • Ok, I found example of fading animation on developer.nokia.com, it works, I can start animation, but only main rectangle goes hidden, can this animation be applied to the whole window?

    @
    Behavior on opacity { PropertyAnimation { duration: 1000 } }

    function onLoggedIn()
    {
        btn_login.text = "Logged in!"
        main_rect.opacity = 0.0
    }
    

    @



  • Ok, setting this params helped:
    @
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setStyleSheet("background:transparent;");
    @

    Now I need to implement drag'ing of this window and custom minimize, maximize and close buttons.


Log in to reply