QT QML 界面设计教程14——图片列表视图控件样式

MyListViewPics.qml

import QtQuick 2.0
import QtQuick.Controls 2.4
//Item {
    ListView{
        id:myListViewPics
        x:15
        //y:15
        width: parent.width-40
        height: 300
        model: patientList
        property int imgWidth: 1
        property int imgHight: 1
        property string imgPath: "qrc:/image/xx.png"
        onFocusChanged: {
            console.log("changed!");
        }
        header:Rectangle{
            id:listHead
            y:parent.y-120
            width: parent.width
            height: 20
            color:"white"
            Label{
                x:parent.x+20
                y:-20
                id:label
                text:"2021/07/29"
                font.pixelSize: 16
                color:"black"
       
             }
         }
        Rectangle{
            y:0
            id:separator1
            border.width: 2
            border.color: "green"
            width: 440
            height: 2
            radius: 0
        }
        delegate: Rectangle {
            height: 200
            width: parent.width
            color: ListView.isCurrentItem?"lightgreen":"white" //选中颜色设置
            y:parent.y+100

            border.color: Qt.lighter(color, 1.1)
            Text {
                x:parent.x

                font.pixelSize: 16
                text: model.getNo //调用每个对象的data()方法
                color: "black"
                anchors.verticalCenter: parent.verticalCenter
                Connections{
                    target: model //监听这个对象
                    onDataChanged:{
                        console.log("changed!");
                    }
                }

            }
            Rectangle{
                id:patientImage
                x:parent.x+180
                y:20
                border.width: 2
                border.color: "green"
                width: myListViewPics.imgWidth
                height: myListViewPics.imgHight
                radius: 0
                Image {
                    id: name
                    source: myListViewPics.imgPath
                    width: myListViewPics.imgWidth
                    height: myListViewPics.imgHight
                }

            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    myListViewPics.currentIndex = index  //实现item切换
                    console.log("click")
                }
            }
        }

    }
//}

调用:

  MyListViewPics{
            y:parent.y
            imgHight: 150
            imgWidth: 400
        }

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值