Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Filter a QListView with the content of a QLineEdit

Filter a QListView with the content of a QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 387 Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Thomas 63
    wrote on last edited by
    #1

    Hi all
    My QListView looks like this:
    736e2212-7c11-4567-9e6e-1d076cb45bfc-grafik.png

    Now I want to filter the first column (Projekt) to the content of a QLineEdit.

    void MainWindow::on_txt_projekt_2_textEdited(const QString &arg1){
        extern QStandardItemModel globalEtiketten;
        QSortFilterProxyModel tempmodel;
        tempmodel.setSourceModel(&globalEtiketten);
        tempmodel.setFilterCaseSensitivity(Qt::CaseInsensitive);
        tempmodel.setFilterKeyColumn(0);
        tempmodel.setFilterWildcard(arg1);
        ui->etikettenView->setModel(&tempmodel);
    }
    

    But after pressing for example "4" in the QLineEdit, the table is empty.

    As the code gets compiled without error, I think I have given some parameter wrong. Who can tell me which one?

    Thank you
    Thomas

    Christian EhrlicherC 1 Reply Last reply
    0
    • T Thomas 63

      Hi all
      My QListView looks like this:
      736e2212-7c11-4567-9e6e-1d076cb45bfc-grafik.png

      Now I want to filter the first column (Projekt) to the content of a QLineEdit.

      void MainWindow::on_txt_projekt_2_textEdited(const QString &arg1){
          extern QStandardItemModel globalEtiketten;
          QSortFilterProxyModel tempmodel;
          tempmodel.setSourceModel(&globalEtiketten);
          tempmodel.setFilterCaseSensitivity(Qt::CaseInsensitive);
          tempmodel.setFilterKeyColumn(0);
          tempmodel.setFilterWildcard(arg1);
          ui->etikettenView->setModel(&tempmodel);
      }
      

      But after pressing for example "4" in the QLineEdit, the table is empty.

      As the code gets compiled without error, I think I have given some parameter wrong. Who can tell me which one?

      Thank you
      Thomas

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Thomas-63 said in Filter a QListView with the content of a QLineEdit:

      QSortFilterProxyModel tempmodel;

      Basic c++ - what's the lifetime of this object?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Thomas 63
        wrote on last edited by
        #3

        Oh, i think it is limited to the function, right?
        Would it help to define it as external like the QStandardItemModel??

        SGaistS 1 Reply Last reply
        0
        • T Thomas 63 has marked this topic as solved on
        • T Offline
          T Offline
          Thomas 63
          wrote on last edited by
          #4

          Yes, that was it! Thanks!

          1 Reply Last reply
          0
          • T Thomas 63

            Oh, i think it is limited to the function, right?
            Would it help to define it as external like the QStandardItemModel??

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Thomas-63 please tell us that you have made it a class member variable and not a static.

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

            1 Reply Last reply
            1

            • Login

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