Qt 在QML中按下时,Tableview行应更改
我的代理是tableview中的图像,如何更改所选行的图像 在按下和释放时,它应该回到原始状态Qt 在QML中按下时,Tableview行应更改,qt,qml,qtquick2,qtableview,Qt,Qml,Qtquick2,Qtableview,我的代理是tableview中的图像,如何更改所选行的图像 在按下和释放时,它应该回到原始状态 itemDelegate: Image { id:item_id height: (tableView.height/(listmodel.count < 4 ? listmodel.count : 4)) source: {
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
}
}
itemdegate:Image
{
id:item\u id
高度:(tableView.height/(listmodel.count<4?listmodel.count:4))
资料来源:
{
var activeRow=tableView.currentRow===styleData.row
(activeRow?图像1:styleData.row%2?(图像2:(图像3))
}
鼠耳
{
id:table\u mouse\u id
锚定。填充:父级
按下按钮:
{
来源=图4
}
发布日期:
{
tableView.currentRow=styleData.row
}
}
您可以使用MouseArea
的pressed
属性:
source: {
var activeRow = tableView.currentRow === styleData.row;
(activeRow ? table_mouse_id.pressed ? image4 //pressed
: Image1 //active
: styleData.row % 2 ? (image2) //odd
: (image3)) //even
}
重要提示:您应该删除
onPressed
处理程序,因为这将覆盖绑定(这可能也是它在当前设置中不起作用的原因)好的,我会试试这个,@Amfasis谢谢你的答案,我对你的答案投了赞成票,但我的声誉分数低于15,这就是为什么这里没有显示,但它被添加了。如果你认为我的答案是解决方案,你可以标记为已接受(如果你不知道怎么做,请参阅)。这也将帮助其他人!使用状态
。它非常清晰易读,为要更改的属性创建一个状态
,并在按下并释放时更改图像
的状态。