qt qml Treeview使用记录--设置每个Item的图片logo,高度

 

这篇帮助很大:

https://blog.csdn.net/qq_32116695/article/details/81298585, 代码如下:

TreeView

{
    
    id: viewTree
    
    anchors.fill: parent
    
    backgroundVisible: false
    
    model: treeViewModel;
    
    sortIndicatorVisible:true
    
    
    
    style:TreeViewStyle{
        
        backgroundColor: "#2B2F33"
        
        textColor: "#666666" //这个是设置分层的时候那个小三角的颜色
        
        itemDelegate:Rectangle{
            
            color: "transparent" //背景设置透明,不然在选中行的时候会出现选中颜色就一半的情况
            
            RowLayout{ //这边的话就看个人的具体需求了,我这边是需要实现 图片+文字
                
                Image {
                    
                    id: name
                    
                    source: if(styleData.value != "默认")
                    
                    {
                        
                        if(styleData.selected)
                        
                        "./Image/分屏视图/" + styleData.row +"_press.png"
                        
                        else if(styleData.value == "1-画面")
                        
                        "./Image/分屏视图/" +"1.png"
                        
                        else if(styleData.value == "4-画面")
                        
                        "./Image/分屏视图/" +"2.png"
                        
                        else if(styleData.value == "9-画面")
                        
                        "./Image/分屏视图/" +"3.png"
                        
                        else if(styleData.value == "16-画面")
                        
                        "./Image/分屏视图/" +"4.png"
                        
                    }
                    
                    else {""}
                    
                }
                
                Text {
                    
                    color: "#FEFEFE"
                    
                    elide: styleData.elideMode
                    
                    text: styleData.value
                    
                    padding: 10
                    
                    onTextChanged: {
                        
                        root.currentItemIndex(styleData.index) //发出信号,这个信号自己定义
                        
                    }
                    
                }
                
            }
            
            
            
        }
        
        rowDelegate:Rectangle{
            
            id: rowDel
            
            color: styleData.selected ? "#595F69" : root.color;
            
            height: 28
            
        }
        
    }
    
    
    
    TableViewColumn { //添加一列
        
        title: "Default"
        
        role: "text"  //这个role的名字要跟你在model中定义的列的名字一模一样,
        
        width: root.width
        
        resizable: false
        
    }
    
    
    
    headerVisible:false
    
    horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
    
    onClicked: {
        
        root.currentChildIndex(viewTree.currentIndex)
        
    }
    
    onDoubleClicked: {
        
        root.currentChildIndex(viewTree.currentIndex)
        
    }
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

First Snowflakes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值