Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 尝试在QML中编辑时,TableView行消失_Qt_User Interface_Qml - Fatal编程技术网

Qt 尝试在QML中编辑时,TableView行消失

Qt 尝试在QML中编辑时,TableView行消失,qt,user-interface,qml,Qt,User Interface,Qml,我正在尝试使用QML和TableView组件,我希望通过编辑一些文本框来更新基础模型。我的问题是,有时该行会从TableView中完全消失,并在单击几下后再次出现。这似乎是随机发生的,可能是在单击行文本下方时发生的 我的执行情况如下: import QtQuick 2.2 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 import QtQuick.Layouts 1.0 import QtQuick.Window 2

我正在尝试使用QML和TableView组件,我希望通过编辑一些文本框来更新基础模型。我的问题是,有时该行会从TableView中完全消失,并在单击几下后再次出现。这似乎是随机发生的,可能是在单击行文本下方时发生的

我的执行情况如下:

import QtQuick 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.0
import QtQuick.Window 2.1


Window {
    visible: true
    width: 538
    height: 360

    ListModel {
        id: mymodel

        ListElement {
            title: "VideoName"
            filesize: "1.5GB"
            length: "20:00"
        }

        ListElement {
            title: "VideoName"
            filesize: "1.5GB"
            length: "20:00"
        }

        ListElement {
            title: "VideoName"
            filesize: "1.5GB"
            length: "20:00"
        }
    }


    ControlView {
        visible: true
        width: parent.width; height: parent.height

        anchors.centerIn: parent

        TableView {
            width: parent.width; height: parent.height
            anchors.centerIn: parent

            TableViewColumn {
                resizable: false
                role: "title"
                title: "Title"
                width: 250
            }

            TableViewColumn {
                role: "filesize"
                title: "Size"
                width: 100
                resizable: false
            }

            TableViewColumn {
                role: "length"
                title: "Length"
                width: 100
                resizable: false

            }

            model: mymodel

            rowDelegate: Rectangle {
                height: 54
            }

            itemDelegate: RowLayout {

                anchors.fill: parent

                Loader{
                    id: loaderEditor
                    sourceComponent: editor
                    Connections {
                        target: loaderEditor.item
                    }

                    Component {
                        id: editor
                        TextInput {
                            id: textinput
                            color: styleData.textColor
                            text: styleData.value

                            onEditingFinished: {
                                mymodel.setProperty(styleData.row, styleData.role,
                                                    loaderEditor.item.text)
                            }

                            MouseArea {
                                id: mouseArea
                                anchors.fill: parent
                                hoverEnabled: true
                                onClicked: {
                                    textinput.forceActiveFocus()
                                    textinput.selectAll()
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
为了突出我的问题,以下是表格最初的显示方式:

我可以尝试编辑列,但如果我在行中单击,而不是直接在文本上单击,则会发生类似的情况


正如你所看到的,那一排已经消失了。我点击一下,它可能会在一段时间后返回,但我不确定是什么原因造成的…

问题是
行代理
。它采用
矩形
组件使用的默认颜色

默认情况下,此颜色为白色

因此,您应该在
rowDelegate
中设置选择行时用于填充行的颜色

例如:

rowDelegate: Rectangle {
    color: styleData.selected ? "#000" : "#fff"
    height: styleData.selected ? 54 : 20
}
height
中的值只是为了根据行选择更清楚地检查行为