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. How to avoid binding loop when binding property to itself + some other property

How to avoid binding loop when binding property to itself + some other property

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 179 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.
  • I Offline
    I Offline
    ioki9
    wrote on 2 May 2023, 23:21 last edited by ioki9 5 Feb 2023, 23:23
    #1

    Hi, I am trying to write header for my table. Right now I am making it resizeble, but upon binding my column width to itself + mouse position I get binding loop. It works, but I am guessing it is a bad solution after all. Do you guys have any suggestion on how to do it the right way?

    Rectangle {
        id:column
        property alias label: columnText.text
        anchors.top: parent.top
        Text{
            id: columnText
            anchors.left: parent.left
            anchors.leftMargin: 5
            anchors.verticalCenter: parent.verticalCenter
            width:parent.width
        }
        MouseArea{
            id:borderMouseArea
            anchors.right: parent.right
            height:parent.height
            width: 5
            hoverEnabled: true
            onPressed: (mouse)=>{
                            mouse.accepted = true
                            parent.width = Qt.binding(function(){return (parent.width + mouseX)})
                            console.log("width:",parent.width,"; mouseX:",mouseX,"; parent.x:",parent.x)
            }
            onReleased:(mouse)=>{
                           parent.width = parent.width
                       }
    
            Rectangle{
                id:columnBorder
                anchors.right: parent.right
                height:parent.height
                width:1
                color:"darkgrey"
            }
            HoverHandler{
                acceptedPointerTypes: PointerDevice.AllDevices
                cursorShape: Qt.SizeHorCursor
            }
        }
    
    }
    
    1 Reply Last reply
    0
    • I ioki9 has marked this topic as solved on 4 May 2023, 12:21
    • I Offline
      I Offline
      ioki9
      wrote on 4 May 2023, 12:23 last edited by
      #2

      i've just used a bit different approach with onMouseXChanged. Here is my solution if someone needs it.

      MouseArea{
              id:borderMouseArea
              anchors.right: parent.right
              height:parent.height
              width: 5
              hoverEnabled: true
              onMouseXChanged: {
                  if(pressed){
                      parent.width = (parent.width + mouseX) >= minColWidth ? (parent.width + mouseX) : parent.width
                  }
              }
      
      1 Reply Last reply
      0

      1/2

      2 May 2023, 23:21

      • Login

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