Поиск в TreaView QML и C ++ - PullRequest
0 голосов
/ 20 июня 2020

В моем проекте я реализую метод поиска в TreeView, но у меня он не работает. Ниже приведен код, над которым я работаю для справки. когда я нажимаю файл, он загружает базу данных, а затем автоматически загружается в представление в виде дерева, я хочу реализовать там метод поиска

введите здесь описание ссылки

код QML ниже:

import QtQuick 2.15
import QtQuick.Layouts 1.14


import QtQuick.Dialogs 1.3
import QtCharts 2.14
import QtQuick.Controls 1.4

import qt.test 1.0

import Qt.labs.qmlmodels 1.0

import Sortfilterproxymodel 1.0

import CanConverter 1.0


ApplicationWindow{



        id:treeview

        visible: true
        width: 800
        height: 800
        title: qsTr("Tree example")

//            Component {
//                id: fakePlace
//                TreeElement {
//                    property string name: getFakePlaceName()
//                    property string population: getFakePopulation()
//                    property string type: "Fake place"
//                    function getFakePlaceName() {
//                        var rez = "";
//                        for(var i = 0;i < Math.round(3 + Math.random() * 7);i ++) {
//                            rez += String.fromCharCode(97 + Math.round(Math.random() * 25));
//                        }
//                        return rez.charAt(0).toUpperCase() + rez.slice(1);
//                    }
//                    function getFakePopulation() {
//                        var num = Math.round(Math.random() * 100000000);
//                        num = num.toString().split("").reverse().join("");
//                        num = num.replace(/(\d{3})/g, '$1,');
//                        num = num.split("").reverse().join("");
//                        return num[0] === ',' ? num.slice(1) : num;
//                    }
//                }
//            }

//            TreeModel {
//                id: treemodel
//                roles: ["name","population","type"]

//                TreeElement {
//                    id:element
//                    property string name: "textarea.text"
//                    property string population: "4,164,252,000"
//                    property string type: "Base de donnée"

//                    TreeElement {
//                        property string name: "China";
//                        property string population: "1,343,239,923"
//                        property string type: "Country"
//                        TreeElement { property string name: "Shanghai"; property string population: "20,217,700"; property string type: "City" }
//                        TreeElement { property string name: "Beijing"; property string population: "16,446,900"; property string type: "City" }
//                        TreeElement { property string name: "Chongqing"; property string population: "11,871,200"; property string type: "City" }

//                    }

//                }
//        //        TreeElement { property string name: "Africa"; property string population: "1,022,234,000"; property string type: "Continent" }
//        //        TreeElement { property string name: "North America"; property string population: "542,056,000"; property string type: "Continent" }
//        //        TreeElement { property string name: "South America"; property string population: "392,555,000"; property string type: "Continent" }
//        //        TreeElement { property string name: "Antarctica"; property string population: "4,490"; property string type: "Continent" }
//        //        TreeElement { property string name: "Europe"; property string population: "738,199,000"; property string type: "Continent" }
//        //        TreeElement { property string name: "Australia"; property string population: "29,127,000"; property string type: "Continent" }
//            }

        toolBar:ToolBar {
            RowLayout {
                anchors.fill: parent


                TextField {
                    id: box

                    placeholderText: "Search..."
                    inputMethodHints: Qt.ImhNoPredictiveText

                    //            width: window.width / 5 * 2
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter
                    onTextChanged: serch.searchString = text
                }


            }

        }


        GroupBox{
             anchors.fill: parent

             Sortfilterproxymodel{
                 id:serch
                 sourceModel: myModel

                 sortRole: Qt.DisplayRole
                 searchString: ""
                 sortOrder: Qt.AscendingOrder


             }


        TreeView {
            id:tree
            anchors.fill: parent


            model: serch
             TableViewColumn {
                title: "Name"
                role: "display"
                width: 200
            }


            onDoubleClicked: {

            }
            onPressAndHold: {

            }
        }
        MessageDialog {
              id: messageDialog
              title: "Info"
          }



        }

    }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...