Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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 QDataWidgetMapper的Qml等价物_Qt_Qml_Model View - Fatal编程技术网

Qt QDataWidgetMapper的Qml等价物

Qt QDataWidgetMapper的Qml等价物,qt,qml,model-view,Qt,Qml,Model View,我有一个基于QAbstractItemModel的树和一个显示其内容的qml树视图。现在我想要一个由两部分组成的UI,左边是TreeView,右边是模型中不同字段的一些输入表单。输入字段应连接/映射到树视图中的当前/选定项 在传统的基于QtWidget的代码中,我使用QDataWidgetMapper来实现这一点,它运行得相当好(现在在Qt5中看起来更好) 作为第一个原型,我使用了两个listView,将seconds delegate.height设置为listView的高度并自动滚动 Lis

我有一个基于QAbstractItemModel的树和一个显示其内容的qml树视图。现在我想要一个由两部分组成的UI,左边是TreeView,右边是模型中不同字段的一些输入表单。输入字段应连接/映射到树视图中的当前/选定项

在传统的基于QtWidget的代码中,我使用QDataWidgetMapper来实现这一点,它运行得相当好(现在在Qt5中看起来更好)

作为第一个原型,我使用了两个listView,将seconds delegate.height设置为listView的高度并自动滚动

ListView {
    id: listView2
    x: 300
    y: 146
    width: 263
    height: 160
    interactive: false
    flickableDirection: Flickable.VerticalFlick
    boundsBehavior: Flickable.StopAtBounds
    snapMode: ListView.SnapOneItem
    clip: true
    currentIndex: core.product.index
    //highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
    focus: true
    delegate: Item {
        width: parent.width
        height: listView2.height
        Row {
            id: row2
            spacing: 10

            Text {
                text: name
                anchors.verticalCenter: parent.verticalCenter
                font.bold: true
            }

            Text {
                text: type
                anchors.verticalCenter: parent.verticalCenter
                font.bold: true
            }

            Loader {
                source: {
                    if (model.type == "SingleGrasp") {
                        "SingleGrasp.qml"
                    } else {
                        "MultGraspTrans.qml"
                    }
                }
            }
        }
    }
    model: core.product.graspModel
}
现在我正在考虑用一个树状视图做同样的事情,但它看起来像一个黑客。你可以在这里看到:

TreeView {
    id: leafView
    x: 300
    y: 146
    width: 263
    height: 160
    clip: true
    focus: true
    TableViewColumn {
        title: "Name"
        role: "name"
    }
    style: TreeViewStyle {
        branchDelegate: Item {}
        indentation: 0
    }

    rowDelegate: Item {
        height: styleData.selected ? leafView.height * 0.99 : 0
    }
    itemDelegate: Item {
        visible: styleData.selected
        x: 5
        width: parent.width
        height: leafView.height
        Row {
            id: row12
            spacing: 10

            Text {
                text: model.name
                anchors.verticalCenter: parent.verticalCenter
                font.bold: true
            }

            Text {
                text: model.type
                anchors.verticalCenter: parent.verticalCenter
                font.bold: true
            }

            Loader {
                source: {
                    if (model.type == "SingleGrasp") {
                        "SingleGrasp.qml"
                    } else {
                        "MultGraspTrans.qml"
                    }
                }
            }
        }
    }
    headerDelegate: Item {}

    model: myModel
    selection: treeView1.selection
    //treeView1 has  selection: SelectionModel{model: myModel}

    function autoExpand(index ) {
        print(index)
        var oneUp = index

        do {

            print(oneUp)
            oneUp = oneUp.parent
            expand(oneUp)
            print("do")
            print(oneUp)
            //print(oneUp.isValid)
        } while (myModel.indexIsValid(oneUp));

    }

    Component.onCompleted: treeView1.selection.currentChanged.connect(autoExpand)
}

将一个扁平化的QuxExtAcro模型编码为当前的所选项目到一个QuastRistStime-类似的模型更合理?

< P>我考虑通过QSORTFILTRYPROXY模型在C++中解决这个问题,但是实际上有一个纯粹的QML解决方案:

TreeView {
   id: myTreeView
   model: myModel
   selection: ItemSelectionModel{ model: myModel }
 }

DelegateModel {
    id: leafViewModel

    groups: [
        DelegateModelGroup {
            name: "current"
            includeByDefault: false
        }
    ]

    filterOnGroup: "current"

    model: myModel
    delegate: Flow{
        Text {
            text: model.name
        }
        TextField {
            id: normalTextField2
            text: model.name
            onEditingFinished: model.name = text
        }
    }
    property var currentIndex: myTreeView.selection.currentIndex

    property int prevIndex: 0

    onCurrentIndexChanged: {
        items.get(prevIndex).inCurrent = false
        rootIndex = currentIndex.parent
        items.get(currentIndex.row).inCurrent = true
        prevIndex = currentIndex.row
    }
}

ListView {
    model: leafViewModel
}

我考虑过用C++中的QSORTFILTRYPROXY模型解决这个问题,但实际上有一个纯粹的QML解决方案:

TreeView {
   id: myTreeView
   model: myModel
   selection: ItemSelectionModel{ model: myModel }
 }

DelegateModel {
    id: leafViewModel

    groups: [
        DelegateModelGroup {
            name: "current"
            includeByDefault: false
        }
    ]

    filterOnGroup: "current"

    model: myModel
    delegate: Flow{
        Text {
            text: model.name
        }
        TextField {
            id: normalTextField2
            text: model.name
            onEditingFinished: model.name = text
        }
    }
    property var currentIndex: myTreeView.selection.currentIndex

    property int prevIndex: 0

    onCurrentIndexChanged: {
        items.get(prevIndex).inCurrent = false
        rootIndex = currentIndex.parent
        items.get(currentIndex.row).inCurrent = true
        prevIndex = currentIndex.row
    }
}

ListView {
    model: leafViewModel
}