Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved PyQt reset tableView

    General and Desktop
    3
    18
    4314
    Loading More Posts
    • 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.
    • mrjj
      mrjj Lifetime Qt Champion @sushmita last edited by mrjj

      @sushmita
      Hehe so that is very different from clearing the view.

      You might want to use a proxy model to do the filtering.
      https://doc.qt.io/qtforpython/PySide2/QtCore/QSortFilterProxyModel.html

      example
      https://stackoverflow.com/questions/14068823/how-to-create-filters-for-qtableview-in-pyqt

      1 Reply Last reply Reply Quote 3
      • S
        sushmita last edited by sushmita

        Hi,
        @mrjj ,

        Thanks for your suggestion, I tried using proxy model.
        With this I can filter fields in same table view.

        But, I am trying to display the filtered data in different table view .
        i.e one main table view will be showing all the entries, and once I enter the key, the filtered data is displayed in other table view.

        So while doing the same I am able to filter data and display in separate table view, but when I am entering new key and pushing button, the table view is displaying the new filtered data along with previous list.

        I.e my need is to refresh the table view every time I enter key and push the button and display new filtered data.

        Thanks,
        Sushmita

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Can you show the code related to the model and filtering ?

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

          S 1 Reply Last reply Reply Quote 1
          • S
            sushmita @SGaist last edited by

            @SGaist

            Sorry, but it is some internal code , and not supposed to share.

            I have created two table views using QAbstractTableModel.
            In 1st table view all entries and filtering data based on key entered and inserting the rows into 2nd model(table view).

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Why a custom table model ? Since you are using a QSortFilterProxyModel, just assign that one to the view showing the filtered data. There's no need for that second model.

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

              S 1 Reply Last reply Reply Quote 1
              • S
                sushmita @SGaist last edited by

                @SGaist said in PyQt reset tabelView:

                QSortFilterProxyModel

                I am not using QSortFilterProxyModel

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Sorry, I misunderstood your answer to @mrjj.

                  In any case, that would likely be the solution. You have a view on your complete data, then on the filtered view, you put the QSortFilterProxyModel as model on top of your main data. That way you don't have to manually add/remove stuff from a secondary model that would duplicate the data already available.

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

                  S 1 Reply Last reply Reply Quote 1
                  • S
                    sushmita @SGaist last edited by sushmita

                    @SGaist

                    Ok. Thanks .
                    I thought of trying without using QSortFilterProxyModel
                    I will try .

                    S 1 Reply Last reply Reply Quote 0
                    • S
                      sushmita @sushmita last edited by

                      Hi,

                      Can we use QSortFilterProxyModel with QAbstractTableModel?
                      Cause the example which was suggested proxy model I referred is using QStandardItemModel.

                      But in my application I am usign QAbstractTableModel for data model.

                      Thanks,
                      Sushmita

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        No problem with that.

                        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 Reply Quote 1
                        • First post
                          Last post