• 4120阅读
  • 1回复

[提问]qt5,如何在TableView表头加入对列内容进行过滤的功能(在表头加入控制,发现这些控制无法获取焦点) [复制链接]

上一主题 下一主题
离线zjhui2013
 

只看楼主 倒序阅读 楼主  发表于: 2015-10-17

各位高手,请教一下:
      下面QML创建了一个TableView,想实列表过滤功能,在表头中加入了一个TextField控件,但发现无法点击进去编辑,感觉是TableView在列表头上做了什么,完成没有将点击传下去给TextField。

Item {
        anchors.fill: parent

        ListModel {
            id: datas
            ListElement {workid: "1234567"; engineer: "aaaa"; }
            ListElement {workid: "123"; engineer: "bbbbb"}
            }

        TableView {
            id: workTable
            anchors.fill: parent
            model: datas
            TableViewColumn {width: 80; movable: false; role: "workid"; title: qsTr("ID")}
            TableViewColumn {width: 80; movable: false; role: "engineer"; title: qsTr("Test")}

            headerDelegate: Rectangle {
                height: 50
                RowLayout {
                    anchors.fill: parent

                    Item {
                        Layout.fillWidth: false
                        Layout.minimumWidth: 0.5
                        Layout.preferredWidth: 0.5
                        Layout.maximumWidth: 0.5

                        height: 1
                    }

                    ColumnLayout {
                        Layout.fillWidth: true
                        Text {
                            Layout.fillWidth: true
                            Layout.fillHeight: false
                            Layout.maximumHeight: 25
                            Layout.minimumHeight: 25
                            Layout.preferredHeight: 25
                            verticalAlignment: Text.AlignBottom
                            elide: Text.ElideRight
                            font.bold: true
                            text: styleData.value
                        }
                        Item {
                            Layout.fillWidth: true
                            Layout.fillHeight: false
                            width: parent.width
                            Layout.maximumHeight: 20
                            Layout.minimumHeight: 20
                            Layout.preferredHeight: 20

                            Row {
                                anchors.fill: parent
                                TextField {
                                    width: parent.width - 18
                                    height: parent.height-2
                                    font.pixelSize: 12
                                    menu: null
                                }

                                Item {
                                    width: 18
                                    height: parent.height

                                }
                            }
                        }
                    }

                    Item {
                        Layout.fillWidth: false
                        Layout.minimumWidth: 0.5
                        Layout.preferredWidth: 0.5
                        Layout.maximumWidth: 0.5

                        height: parent.height

                        Rectangle {
                            width: parent.width
                            height: parent.height-10
                            anchors.centerIn: parent
                            radius: 3
                            color: "#94C668"
                        }
                    }
                }
            }
        }
    }
离线zjhui2013

只看该作者 1楼 发表于: 2015-10-19
找到原因了。。这是qt的bug吧,要把basictableview.qml中的mousearea(id:headerclickarea)的z属性设置为-1
快速回复
限100 字节
 
上一个 下一个