qt quick中如何实现替换掉原来属性的默认值且保持一些内容不变呢?



  • 我的题目可能有点绕哈.

    我有一个property,他的布局是被设定了的。但是如果用户替换掉这个property,怎么才能保持他的布局是和原来的一样呢?

    举例子:

      Bar{
       id: titleBar
       //left controls
    
       property Item leftControls:
           ControlsList{
               parent: titleBar
               anchors.left: parent.left
               anchors.verticalCenter: parent.verticalCenter
           }
    
       //right controls
       property Item rightControls:
           ControlsList{
               parent: titleBar
               anchors.right: parent.right
               anchors.verticalCenter: parent.verticalCenter
           }
      }
    

    我想在***leftControls***或者***rightControls***被替换的时候,他的布局总是最初默认的布局。

    怎么实现呢?



  • @Accelerated

    Bar{
        id: titleBar
        //left controls
    
        property Item leftControls: ControlsList{ }
    
        //right controls
        property Item rightControls: ControlsList{ }
        Binding {
           target: leftControls
           property: "parent"
           value: titleBar
        }
        Binding {
           target: leftControls
           property: "anchors.left"
           value: titleBar.left
        }
        Binding {
           target: leftControls
           property: "anchors.verticalCenter"
           value: titleBar.verticalCenter
        }
    
        Binding {
           target: rightControls
           property: "parent"
           value: titleBar
        }
        Binding {
           target: leftControls
           property: "anchors.left"
           value: titleBar.left
        }
        Binding {
           target: leftControls
           property: "anchors.verticalCenter"
           value: titleBar.verticalCenter
        }
    }
    


  • @qyvlikqt quick中如何实现替换掉原来属性的默认值且保持一些内容不变呢? 中说:

    //left controls
    
    property Item leftControls: ControlsList{ }
    
    //right controls
    property Item rightControls: ControlsList{ }
    Binding {
       target: leftControls
       property: "parent"
       value: titleBar
    }
    Binding {
       target: leftControls
       property: "anchors.left"
       value: titleBar.left
    }
    Binding {
       target: leftControls
       property: "anchors.verticalCenter"
       value: titleBar.verticalCenter
    }
    
    Binding {
       target: rightControls
       property: "parent"
       value: titleBar
    }
    Binding {
       target: leftControls
       property: "anchors.left"
       value: titleBar.left
    }
    Binding {
       target: leftControls
       property: "anchors.verticalCenter"
       value: titleBar.verticalCenter
    }
    

    我试试哈~



  • @qyvlik 由于ControlsList是继承Row的,运行了代码后。提示:

      QML Row: Cannot anchor to an item that isn't a parent or sibling.
    

    我需要改变它吗?



  • @Accelerated 要,做一些调整,代码总体框架是没错的。


 

最近的回复

  • @bladesero Blender 在角色建模和渲染这些方面的确比较强。😄

    我们的软件还在发展中呢。
    18da2116-2055-47c1-8317-1ccde17dfcc0-image.png

    阅读更多
  • untitled.jpg figure角色(WIP2).jpg
    TIM截图20190117184210.png
    使用的软件是blender,zbrush和substance painter

    阅读更多
  • 背景:如果需要qml显示循环list,一般是用3个ListView循环交替,实现伪循环,期间逻辑复杂,容易出错,PathView本身自带循环,所以考虑用PathView实现循环

    设计:PathView显示5条数据,按照垂直List一个个排好顺序,由于收尾移动时候会空白穿帮,所以用clip控制显示中间三条数据

    滚动控制:currentIndex,decrementCurrentIndex(),incrementCurrentIndex()

    代码:

    Item{ id: item1 property int myIndex: 0 property int onePageCount: 3 property real oneHeight: 72 property real oneWidth: 580 property int isCurrentListView: 1 //0,1,2 property bool isAdd: true //direction,down=true,up=false property int hightlightIndex: 0 property int currentIndexPathView: 0 //use this Item{ id: itemClip width: item1.oneWidth height: item1.oneHeight*3 clip: true PathView { id: listView1 width: item1.oneWidth model: listModelSpeedWarning delegate: delegeteLine pathItemCount: item1.onePageCount+2 interactive: false path: Path { startX: item1.oneWidth/2 startY: -item1.oneHeight/2 PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*0+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*0+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*1+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*1+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*2+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*2+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*3+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*3+item1.oneHeight/2 } PathQuad { x: item1.oneWidth/2; y: item1.oneHeight*4+item1.oneHeight/2; controlX: item1.oneWidth/2; controlY: item1.oneHeight*4+item1.oneHeight/2 } } Component.onCompleted: { listView1.currentIndex = -1 } } } }

    问题:windows下测试,按住按键不松手,list滚动会卡住,松手后恢复正常,看来list不能滚动太快

    阅读更多
  • H

    @青山白云 只是为了替换GIF,不过目前已经解决加载问题

    阅读更多

关注我们

微博
QQ群











召唤伊斯特瓦尔