如何在保持其他默认值的同时覆盖 TableView.rowDelegate 的某些属性
How to override some properties of TableView.rowDelegate while keeping others default
我正在使用 rowDelegate
实现可变行高,如下所示。但是,它不使用 selected/alternate 行的默认背景颜色。我怎样才能保留我不想覆盖的所有默认值?
TableView {
id: messagesTable
TableViewColumn {
role: "severity"
title: ""
width: 20
delegate: Image {
anchors.centerIn: parent
fillMode: Image.Pad
source: iconSources[styleData.value.toLowerCase()]
}
}
TableViewColumn {
role: "message"
title: "Message"
width: 300
}
TableViewColumn {
role: "source"
title: "File"
width: 150
}
TableViewColumn {
role: "startLine"
title: "Line"
width: 40
}
TableViewColumn {
role: "startColumn"
title: "Column"
width: 50
}
rowDelegate: Rectangle {
width: childrenRect.width
height: (messagesModel.get(styleData.row).lineCount || 1) * 20
}
model: messagesModel
}
你不能。
使用 Qt Quick Controls 设计样式的一般规则是:一旦覆盖委托,就从头开始。例如,如果样式提供了 DefaultTableViewRowDelegate
类型,您可以构建它的一个实例然后它就可以工作,但是由于默认委托是内联编写的,您无法访问它们。
我正在使用 rowDelegate
实现可变行高,如下所示。但是,它不使用 selected/alternate 行的默认背景颜色。我怎样才能保留我不想覆盖的所有默认值?
TableView {
id: messagesTable
TableViewColumn {
role: "severity"
title: ""
width: 20
delegate: Image {
anchors.centerIn: parent
fillMode: Image.Pad
source: iconSources[styleData.value.toLowerCase()]
}
}
TableViewColumn {
role: "message"
title: "Message"
width: 300
}
TableViewColumn {
role: "source"
title: "File"
width: 150
}
TableViewColumn {
role: "startLine"
title: "Line"
width: 40
}
TableViewColumn {
role: "startColumn"
title: "Column"
width: 50
}
rowDelegate: Rectangle {
width: childrenRect.width
height: (messagesModel.get(styleData.row).lineCount || 1) * 20
}
model: messagesModel
}
你不能。
使用 Qt Quick Controls 设计样式的一般规则是:一旦覆盖委托,就从头开始。例如,如果样式提供了 DefaultTableViewRowDelegate
类型,您可以构建它的一个实例然后它就可以工作,但是由于默认委托是内联编写的,您无法访问它们。