简体   繁体   English

如何使用 QT Quick Contol 2.0 为 TableView 中的一行提供边框颜色?

[英]How to give border-color to a row in TableView with QT Quick Contol 2.0?

Table1表格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"
                        }

                    }
                }
            }

Table2表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"

         }
    }
}

effect影响

It is easy to make with rowDelegate at QtQuick Controls version 1.0 .在 QtQuick Controls version 1.0 中使用 rowDelegate 很容易制作。 I have no idea for setting border-color for row item while row selected.我不知道在选择行时为行项目设置边框颜色。 It seems border-color can only be set for each item in a row.似乎只能为一行中的每个项目设置边框颜色。

I made it with other four rectangles finally :)我终于用其他四个矩形做了它:)
like this:像这样:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM