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

问题描述 投票:0回答:1

我的委托是tableview中的图像,如何更改在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
                    }
                }
qt qml qtquick2 qtableview
1个回答
1
投票

您可以使用pressedMouseArea属性:

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

重要说明:您应该删除onPressed处理程序,因为这将覆盖绑定(这可能也是它在您当前设置中不起作用的原因)

© www.soinside.com 2019 - 2024. All rights reserved.