[英]How to give border-color to a row in TableView with QT Quick Contol 2.0?
表格1
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"
}
}
}
}
表2
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"
}
}
}
影響
在 QtQuick Controls version 1.0 中使用 rowDelegate 很容易制作。 我不知道在選擇行時為行項目設置邊框顏色。 似乎只能為一行中的每個項目設置邊框顏色。
我終於用其他四個矩形做了它:)
像這樣:
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) }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.