Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Load qml state from other file
Qt 6.11 is out! See what's new in the release blog

Load qml state from other file

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi, I want to write qml state in separate files, so I can use the same state and transition in different components
    This is a simple example
    main.qml

    @import QtQuick 1.1

    Rectangle {
    width: 360
    height: 360
    Rectangle {
    id: rect
    width: 60
    height: 60
    x: parent.width/2

        Component.onCompleted: {
            state = "right"
        }
    
        states: [
            RightState{}
        ]
    }
    

    }
    @

    RightState.qml

    @
    import QtQuick 1.1

    State {
    name: "right"
    PropertyChanges {
    target: parent
    x: 500
    }
    }
    @

    the problem is that I don't know how to specify the target of propertyChanges, does anyone know how can do that?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I want to create an animation editor, so I need to create some special effects, such as fly in , scale and so on, in order to apply these effects to different items, I want to store states in separate files, so I can assign state to item directly

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        the key point is how to delay setting the target of propertychanges

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Hello hailong,

          You can use the following code in your RightState.qml :
          @ property Item myItem : theIdOfTheItem
          @
          for each kind of item you want.
          Then in the main.qml, you can set the real myItem you want @states: [
          RightState{
          myItem : Item{...} or theRealId
          }
          ]@
          I haven't done it tought, so please tell me if it works

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Hi, Thank you very much :) this works

            [quote author="dmcr" date="1352275114"]Hello hailong,

            You can use the following code in your RightState.qml :
            @ property Item myItem : theIdOfTheItem
            @
            for each kind of item you want.
            Then in the main.qml, you can set the real myItem you want @states: [
            RightState{
            myItem : Item{...} or theRealId
            }
            ]@
            I haven't done it tought, so please tell me if it works[/quote]

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved