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 6101787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:32:23+00:00 2026-05-23T13:32:23+00:00

Is it possible to use different transition animations between two states in a QML

  • 0

Is it possible to use different transition animations between two states in a QML component? The following example doesn’t work and the program crashes (segmentation fault on Linux):

import QtQuick 1.0

Rectangle {
    id: canvas
    height: 500; width: 600

    Rectangle { id: rect; color: "#04A"; height: 100; width: 100 }

    state: "A"
    states: [
        State { name: "A"; PropertyChanges { target: rect; x: 0; y: 100 } },
        State { name: "B"; PropertyChanges { target: rect; x: 500; y: 100 } }
    ]


    transitions: trans1

    property list<Transition> trans1: [
        Transition {
            NumberAnimation { target: rect; property: "x"; duration: 500 }
        }
    ]

    property list<Transition> trans2: [
        Transition {
            from: "A"; to: "B"
            SequentialAnimation {
                NumberAnimation { target: rect; property: "x"; from: 0; to: -100; duration: 250 }
                NumberAnimation { target: rect; property: "x"; from: 600; to: 500; duration: 250 }
            }
        },
        Transition {
            from: "B"; to: "A"
            SequentialAnimation {
                NumberAnimation { target: rect; property: "x"; from: 500; to: 600; duration: 250 }
                NumberAnimation { target: rect; property: "x"; from: -100; to: 0; duration: 250 }
            }
        }
    ]


    // test script /////////////////////////////////////////////////////////

    Timer { interval: 1000; running: true; onTriggered: canvas.state = "B" }
    Timer { interval: 2000; running: true; onTriggered: canvas.state = "A" }

    // change kind of transition
    Timer { interval: 3000; running: true; onTriggered: canvas.transitions = trans2 }

    Timer { interval: 4000; running: true; onTriggered: canvas.state = "B" }
    Timer { interval: 5000; running: true; onTriggered: canvas.state = "A" }
}

The QML-Doc says that the transtition property is read-only, but usually a list of Transition{...} elements is assigned to this property, so it can’t be really read-only, can it?

One solution would be to use 4 states, e.g. A1, B1, A2 and B2, and define a transition between A1 and B1, that looks like trans1 and another transition between A2 and B2, that looks like trans2.
But I want to know if something like this is possible without introducing new states.


Edit:

The suggestion of gregschlom to change the from/to properties works, here an example:

import QtQuick 1.0

Rectangle {
    id: canvas
    height: 500; width: 600

    Rectangle { id: rect; color: "#04A"; height: 100; width: 100 }

    state: "A"
    states: [
        State { name: "A"; PropertyChanges { target: rect; x: 0; y: 100 } },
        State { name: "B"; PropertyChanges { target: rect; x: 500; y: 100 } }
    ]


    property int transType: 1

    transitions: [
        Transition {
            from: transType == 1 ? "*" : "none"
            to:   transType == 1 ? "*" : "none"
            ParallelAnimation {
                RotationAnimation { target: rect; property: "rotation"; from: 0; to:360; duration: 500 }
                NumberAnimation { target: rect; property: "x"; duration: 500 }
            }
        },
        Transition {
            from: transType == 2 ? "*" : "none"
            to:   transType == 2 ? "*" : "none"
            NumberAnimation { target: rect; property: "x"; duration: 500 }
        }
    ]


    // test script /////////////////////////////////////////////////////////

    Timer { interval: 1000; running: true; onTriggered: canvas.state = "B" }
    Timer { interval: 2000; running: true; onTriggered: canvas.state = "A" }

    // change kind of transition
    Timer { interval: 3000; running: true; onTriggered: canvas.transType = 2 }

    Timer { interval: 4000; running: true; onTriggered: canvas.state = "B" }
    Timer { interval: 5000; running: true; onTriggered: canvas.state = "A" }
}
  • 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-05-23T13:32:23+00:00Added an answer on May 23, 2026 at 1:32 pm

    The following example doesn’t work and the program crashes (segmentation fault on Linux):

    Please, do report crashes like that to https://bugreports.qt.io. Crashes are given maximum priority and are usually fixed in a few days.

    The QML-Doc says that the transtition property is read-only, but usually a list of Transition{…} elements is assigned to this property, so it can’t be really read-only, can it?

    I think assigning at run-time (ie: in a script) is different than assigning in your qml file, so when the say “read-only” maybe they meant you’re not supposed to change the value once it has been initialized.

    Anyways, if the doc say it’s read-only, and it crashes when you try to write to it, then you know you’re probably not supposed to do it… 🙂

    But I want to know if something like this is possible without introducing new states.

    The qml doc on Transitions says:

    If multiple Transitions are specified, only a single (best-matching) Transition will be applied for any particular state change. In the example above, when changing to state1, the first transition will be used, rather than the more generic second transition.

    So you could try be defining all your transitions at once and change the “to” and “from” settings dynamically to try to enable / disable a transition. Not sure if it’s possible, but it could work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use different Oracle schemas in Crystal Reports and change between
Is it possible to use different choices for subclasses of models? The following code
Is it possible to use BackGroundWorker thread in ASP.NET 2.0 for the following scenario,
Is it possible to use different excel sheets for different test methods sharing the
Is possible to use different version of Perl without using the SET or manipulating
I try to use two different jqgrid on the same page with the mvc
We're exploring different approaches for communicating between two different SQL Server instances. One of
Using C#, is it possible to use OleDbTransaction to execute a insert in two
Is it possible for both rotateX and rotateY in CSS3 to have different transition
I have recently started looking into Google Charts API for possible use within the

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.