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. Is it possible to define another set of states in the same qml file
Forum Updated to NodeBB v4.3 + New Features

Is it possible to define another set of states in the same qml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 248 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.
  • J Offline
    J Offline
    James A
    wrote on last edited by
    #1

    I wanted to define two different states for two different components in the same qml file

    Example :

    Text { id : text }

    Button { id : button }

    // states for the text filed
    states: [
    State {
    name: "charging"
    PropertyChanges {
    target: text
    text: "charging"
    }
    },
    State{
    name: "discharging"
    PropertyChanges {
    target: text
    text: "discharging"
    }
    }
    ]

    // states for the button
    states: [
    State {
    name: "pressed"
    PropertyChanges {
    target: button
    color: "read"
    }
    },
    State{
    name: "released"
    PropertyChanges {
    target: button
    text: "black"
    }
    }
    ]

    // wanted to assign states to text and button component
    text.state = "charging"
    button.state = "pressed"

    Note : text and button state update will be asynchronous.
    Want to the correct way to assign states to text and buttons ?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by GrecKo
      #2

      Define the states in each object.

      Text {
          id: text
          states: [
              State {
                  name: "charging"
                  ...
              },
              ...
          ]
      }
      
      Button {
          id: button
          states: [
              State {
                  name: "pressed"
                  ...
              },
              ...
          ]
      }
      

      Also please encase your code in triple backticks ``` for multiline blocks and single backtick ` for inline snippets.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        James A
        wrote on last edited by
        #3

        @GrecKo

        Thanks for helping out

        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