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. Link two object attributes to each other
Forum Updated to NodeBB v4.3 + New Features

Link two object attributes to each other

Scheduled Pinned Locked Moved Solved QML and Qt Quick
link attributes
2 Posts 2 Posters 545 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.
  • GrekG Offline
    GrekG Offline
    Grek
    wrote on last edited by
    #1

    I'm new to QT and have a question about linking two attributes to eachother.
    I want to be able to alter one which should change the other.

    example:

            TextField{
                id:textBox
                text:slideBox.x
                validator: IntValidator{
                    top: 255
                    bottom: 0
                    }
                maximumLength: 3
            }
    
            Rectangle{
                id:slideBox
                width: 10
                height: 15
                anchors.fill: parent
                border.width: 1
                x : textBox.text
    
                MouseArea {
                    anchors.fill: parent
                    drag.target: parent
                    drag.threshold: 0
                    drag.maximumX: 400
                    drag.minimumX: 30
                }
            }
    

    Here "slideBox.x" is changed by the text field and "TextField.text" is changed by dragging the box. I know that this creates a nasty loop but I hope you get the idea of what I want to do. Is this possible to do in a good way?

    M 1 Reply Last reply
    0
    • GrekG Grek

      I'm new to QT and have a question about linking two attributes to eachother.
      I want to be able to alter one which should change the other.

      example:

              TextField{
                  id:textBox
                  text:slideBox.x
                  validator: IntValidator{
                      top: 255
                      bottom: 0
                      }
                  maximumLength: 3
              }
      
              Rectangle{
                  id:slideBox
                  width: 10
                  height: 15
                  anchors.fill: parent
                  border.width: 1
                  x : textBox.text
      
                  MouseArea {
                      anchors.fill: parent
                      drag.target: parent
                      drag.threshold: 0
                      drag.maximumX: 400
                      drag.minimumX: 30
                  }
              }
      

      Here "slideBox.x" is changed by the text field and "TextField.text" is changed by dragging the box. I know that this creates a nasty loop but I hope you get the idea of what I want to do. Is this possible to do in a good way?

      M Offline
      M Offline
      medyakovvit
      wrote on last edited by
      #2

      @Grek

      TextField{
                  id:textBox
                  text: slideBox.x
                  validator: IntValidator{
                      top: 255
                      bottom: 0
                      }
                  maximumLength: 3
      
                  // onEditingFinished or onTextChanged or onAccepted( choose which fits better )
                  onEditingFinished: slidebox.x = parseInt(text)
              }
      
              Rectangle{
                  id:slideBox
                  width: 10
                  height: 15
                  anchors.fill: parent
                  border.width: 1
                  //x : textBox.text  
      
                  MouseArea {
                      anchors.fill: parent
                      drag.target: parent
                      drag.threshold: 0
                      drag.maximumX: 400
                      drag.minimumX: 30
                  }
              }
      
      1 Reply Last reply
      1

      • Login

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