在矩形内包装ListView

时间:2015-04-21 17:35:33

标签: qt listview qml

我的问题是当我滚动ListView元素时,元素滚动矩形边框但是我已将ListView包装在Rectangle内。如何使元素滚动而不影响Rectangle边框。

以下是结果链接 https://drive.google.com/file/d/0Bx616yTb6y_xQzNxRy1UcktrVzA/view?usp=sharing https://drive.google.com/file/d/0Bx616yTb6y_xdl9CbWt4MTJ3Smc/view?usp=sharing

以下是代码

        ListModel{
        id: mod
    }
        Rectangle{
        id:listviewrec
        x: 347
        y:644
        width: 700
        height: 91
        radius: 4
        border.color:"#7CC7FF"
        border.width: 4
         visible: true

            ListView{
                id:modlistview
                width: listviewrec.width
                height: listviewrec.height
                clip: true
                boundsBehavior: Flickable.DragOverBounds
                spacing:25
                model:mod
                delegate: delegateimage
                orientation: Qt.Horizontal
                anchors.fill: listviewrec


            }

        }


    Component{
        id:delegateimage
        Item{
            id:imageitem
            width:50
            height:60
            visible:true
            Rectangle{
                id:imagerec
                x:10
                y:6
                width: 60
                height:70                    
                border.color: "#7CC7FF"
                border.width: 5
                radius: 2
                visible:true
                Image{
                    x: 3
                    y: 3
                    height : imagerec.height
                    visible: true
                    width : imagerec.width
                    anchors.fill: imagerec
                    source:fileUrl
                }
                                }
        }
    }

2 个答案:

答案 0 :(得分:3)

就边界而言,我认为qml不具有内部和外部的概念,(或者如果确实如此,边框是在内部直线绘制的,因此孩子将被绘制在顶部)。 / p>

你最好的选择是做这样的事情:

Item {
  id:listviewrec
  x: 347
  y:644
  width: 700
  height: 91
  visible: true

  ListView{
    id:modlistview
    width: listviewrec.width
    height: listviewrec.height
    clip: true
    boundsBehavior: Flickable.DragOverBounds
    spacing:25
    model:mod
    delegate: delegateimage
    orientation: Qt.Horizontal
    anchors.fill: listviewrec
  }

  Rectangle {
    radius: 4
    border.color:"#7CC7FF"
    border.width: 4
    color: 'transparent'
    anchors.fill: parent
  }
}

它只是在ListView

之上绘制一个带有所需边框的透明矩形

答案 1 :(得分:0)

目前我无法运行您的代码,但似乎需要删除明确的宽度和高度设置,因为您使用的是anchors.fill