如何使用QT Quick Control 2.0为TableView中的行指定边框颜色?
表1 表2如何使用QT Quick Control 2.0为TableView中的行指定边框颜色?,qt,qml,tableview,qtquickcontrols,Qt,Qml,Tableview,Qtquickcontrols,表1 表2 Item { id: control TableView { id: table1 delegate: Rectangle { color: control.selected === row ? "pink" : "white"
Item {
id: control
TableView {
id: table1
delegate: Rectangle {
color: control.selected === row ? "pink" : "white"
border.color: control.selected === row?"lightblue":"transparent"
border.width: 2
Text {
text: display
color: "black"
}
}
}
}
影响
在QtQuick Controls 1.0版上使用rowDelegate很容易实现。
我不知道在选择行时为行项目设置边框颜色。
似乎只能为一行中的每个项目设置边框颜色。我最后用其他四个矩形做了:)
像这样:
TableView{
id :tableView
headerDelegate:Rectangle{
color : "transparent"
Text
{
text: styleData.value
}
}
rowDelegate: Rectangle {
color : styleData.selected ? "pink" : "white"
border.color: styleData.selected ?"lightblue":"transparent"
}
itemDelegate: Rectangle{
color : "transparent"
Text {
color : "black"
text: styleData.value
}
}
style: TableViewStyle{
backgroundColor : "transparent"
}
}
}
Rectangle { anchors.top: parent.top; height: item_table.borderWidth; width: parent.width; color: isSelect()?borderColor:"transparent"}
Rectangle { anchors.bottom: parent.bottom; height: item_table.borderWidth; width: parent.width; color: isSelect()?borderColor:"transparent"}
Rectangle { anchors.left: parent.left; height: parent.height; width: item_table.borderWidth; color: borderColor; visible: (isSelect()&&column === 0) }
Rectangle { anchors.right: parent.right; height: parent.height; width: item_table.borderWidth; color: borderColor; visible: (isSelect()&&column === tableView.columns - 1) }