简体   繁体   English

在QML中按下时,Tableview行应更改

[英]Tableview row should change on pressed in QML

My delegate is image in tableview, How to change image of row which is selected onPressed and onReleased it should go back in it's original state. 我的代表是表视图中的图像,如何更改在onPressed和onReleased中选择的行的图像,它应该返回到其原始状态。

itemDelegate: Image
            {
                id:item_id
                height: (tableView.height/(listmodel.count < 4 ? listmodel.count : 4))
                source:
                {
                    var activeRow = tableView.currentRow === styleData.row
                    (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                }

                MouseArea
                {
                    id:table_mouse_id
                    anchors.fill: parent

                    onPressed:
                    {
                       source = image 4
                    }

                    onReleased:
                    {
                        tableView.currentRow = styleData.row
                    }
                }

You can use the pressed property of the MouseArea : 您可以使用MouseAreapressed属性:

source: {
            var activeRow = tableView.currentRow === styleData.row;
            (activeRow ? table_mouse_id.pressed ? image4 //pressed
                                                : Image1 //active
                       : styleData.row % 2 ? (image2)  //odd
                                           : (image3)) //even
        }

Important note: you should remove the onPressed handler, as this will override the binding (which is probably also the reason it's not working in your current setup) 重要说明:您应该删除onPressed处理程序,因为这将覆盖绑定(这也可能是它在当前设置中不起作用的原因)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM