Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Filtring TreeView QML
QtWS25 Last Chance

Filtring TreeView QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
treeviewqmlqtcppfiltring
8 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ENSAO_CHEIKH
    wrote on last edited by
    #1

    Hi everyone, so in my project I intend to do searching method to filter Treeview after filling a text field but i cant catch the way to do it, this is the code

    import QtQuick 2.15
    import QtQuick.Layouts 1.14
    import QtQuick.Controls 1.4
    
    ApplicationWindow{
    
    
    
            id:tree
    
            visible: true
            width: 800
            height: 800
            title: qsTr("Tree example")
    
    
            GroupBox{
                 anchors.fill: parent
    
    
    
    
            TreeView {
                id:treee
                anchors.fill: parent
    
    
                model: myModel
                 TableViewColumn {
                    title: "Name"
                    role: "display"
                    width: 200
                }
    
    
                onDoubleClicked: {
    
                }
                onPressAndHold: {
    
                }
            }
            MessageDialog {
                  id: messageDialog
                  title: "Info"
              }
    
    
    
            }
    
        }
    
    

    cpp code is below :

    #ifndef TREEVIEWMODEL_H
    #define TREEVIEWMODEL_H
    
    #include <QObject>
    #include<QStandardItemModel>
    
    
    class TreeViewModel : public QStandardItemModel
    {
        Q_OBJECT
    public:
         TreeViewModel(QObject *parent = nullptr);
    
    signals:
    
    public slots:
         void readDataBase();
    
    
    };
    
    #endif // TREEVIEWMODEL_H
    
    #include "treeviewmodel.h"
    #include <QStandardItem>
    
    
    TreeViewModel::TreeViewModel(QObject *parent) : QStandardItemModel{parent}
    {
        CanConverter canConverter;
    
        //connect(canConverter.getInstance(),SIGNAL(dataLoaded()),this,SLOT(readDataBase()));
        setColumnCount(1);
        QStandardItem *rootItem=invisibleRootItem();
    
        QStandardItem *DataBase1= new QStandardItem;
        QStandardItem *DataBase2 =new QStandardItem;
        QStandardItem *DataBase3= new QStandardItem;
    
    
        QStandardItem *Trame1=new QStandardItem;
        QStandardItem *Trame2=new QStandardItem;
        QStandardItem *Trame3=new QStandardItem;
        QStandardItem *Trame4=new QStandardItem;
        QStandardItem *Trame5=new QStandardItem;
        QStandardItem *Trame6=new QStandardItem;
        //QStandardItem *Trame7=new QStandardItem;
    
    
        DataBase1->setText("base de donné 1");
        DataBase1->setText("base de donné 2");
        DataBase1->setText("base de donné 3");
    
        Trame1->setText("Trame1");
        Trame2->setText("Trame2");
        Trame3->setText("Trame3");
        Trame4->setText("Trame4");
        Trame5->setText("Trame5");
        Trame6->setText("Trame6");
    
    
    
        rootItem->appendRow(DataBase1);
        rootItem->appendRow(DataBase2);
        rootItem->appendRow(DataBase3);
    
    
        DataBase1->appendRow(Trame1);
        DataBase1->appendRow(Trame2);
    
        DataBase2->appendRow(Trame3);
        DataBase2->appendRow(Trame4);
    
        DataBase3->appendRow(Trame5);
        DataBase3->appendRow(Trame6);
    
    
    
    }
    
    1 Reply Last reply
    0
    • E Offline
      E Offline
      ENSAO_CHEIKH
      wrote on last edited by
      #2

      Pleaase is there any solution for that

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        https://doc.qt.io/qt-5/qsortfilterproxymodel.html

        C++ is a perfectly valid school of magic.

        E 1 Reply Last reply
        0
        • fcarneyF fcarney

          https://doc.qt.io/qt-5/qsortfilterproxymodel.html

          E Offline
          E Offline
          ENSAO_CHEIKH
          wrote on last edited by ENSAO_CHEIKH
          #4

          @fcarney , thans for your reply, but when i use it, implementing the code below of filtring
          b2e24dc0-00d6-445b-a720-93ff86457a0d-image.png

          so I get the problem when filtring, and the childrens of nodes wasn't shown, if i don't exapnd the nodes
          69c2a2e0-ca40-4a66-bf3e-7a6475e26fae-image.png
          pleaase is there any solution, it's been 4 days I m struglling with it

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ENSAO_CHEIKH
            wrote on last edited by
            #5

            Is there any solution for that please, I don't Know if I m doing wrong while implementing this filterAcceptRow(), is the syntax right?

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ENSAO_CHEIKH
              wrote on last edited by
              #6

              Hi, evreyOne, so I tried also, the findItem() method but it'is not working well, and I want to use the QProxySortFilterModel, implemeting the method filterAcceptRow(), I did it but also work with some problems, I think that I don't implement it right pleease need help

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                You are filtering a tree model, you have to allow for the child items to pass your filter.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                E 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  You are filtering a tree model, you have to allow for the child items to pass your filter.

                  E Offline
                  E Offline
                  ENSAO_CHEIKH
                  wrote on last edited by
                  #8

                  @SGaist thanks a lots for your reply, bu how to do it?

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved