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. Changing properties of multiple targets per state
Forum Updated to NodeBB v4.3 + New Features

Changing properties of multiple targets per state

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 3.1k Views
  • 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.
  • M Offline
    M Offline
    MilloMille
    wrote on last edited by
    #1

    Hello,
    I have a simple problem but i cant seem to find a solution. For letting the user chose one of multiple items, i wanted somthing like a wheel with the middle item beeing the chosen item. You might now similar or identical designs from your cell phone when you set your alarm to a certain time.
    I thought the easiest way would be to set three rectangles as placeholders and define states with transitions to make the images move from rectangle to rectangle. Here is an extract from the code:

    Image {id: image1; ....}
    Image {id: image2; ....}
    Image {id: image3; ....}
    
    Rectangle{id: leftrec; anchors.left: parent.left: ....}
    Rectangle{id: middlerec; anchors.centerIn: parent: ....}
    Rectangle{id: rightrec; anchors.right: parent.right: ....}
    
    StateGroup{
        id: stategroup
        states: [
            State {
                name: "State1"
                PropertyChanges {target: image1; x: leftrec.x; .....}
                PropertyChanges {target: image2; x: middlerec.x; ....}
                PropertyChanges {target: image3; x: rightrec.x; ....}
            },
            State{
                name: "State2"
                PropertyChanges {target: image3; x: leftrec.x; .....}
                PropertyChanges {target: image1; x: middlerec.x; ....}
                PropertyChanges {target: image2; x: rightrec.x; ....}
            },
            State{
                name: "State3"
                PropertyChanges {target: image2; x: leftrec.x; .....}
                PropertyChanges {target: image3; x: middlerec.x; ....}
                PropertyChanges {target: image1; x: rightrec.x; ....}
            }
        ]
        transitions: [
            Transition {
                from: "State1"; to: "State2"
                NumberAnimation {properties: "x,y,width,height"; duration: 1000}
            },
            // and so on...  I think you get the drill
    

    When I execute the code the following happens:
    Only the properties of the first target are changing. But for some reason the properties of the second target are applied to my first target. I dont really understand why this is happening, I checked all the IDs and they seem to be ok.

    PS: Please dont worry that my transition form rightrec to leftrec will look like shit, in the actual code I took care of that problem.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You have anchored and using x value as well. When you use the anchors, setting x values will not work. Remove your anchor settings. Everything should work fine.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      8
      • M Offline
        M Offline
        MilloMille
        wrote on last edited by
        #3

        Damn you are right. But the anchors are only on the Rectangle, which dont move anyway. Why do the anchors on the fixed rectangles matter?

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Anchors always have precedence over x and y. Does not matter which items

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          9

          • Login

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