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. PyQt reset tableView
Forum Updated to NodeBB v4.3 + New Features

PyQt reset tableView

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 6.3k Views 3 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.
  • mrjjM mrjj

    Hi
    So when you say "clear the view"
    do you want to delete the data from the model or simply
    remove the whole model from the view?

    The view only displays the data. and while it can filter it or sort it,
    the model is the one that can clear the data.
    If by clear you mean delete it.
    Normally that would happen by removing the data from the original data structure
    that is feeding the model.

    S Offline
    S Offline
    sushmita
    wrote on last edited by
    #6

    @mrjj

    I just don't want to display data in view.

    mrjjM 1 Reply Last reply
    0
    • S sushmita

      @mrjj

      I just don't want to display data in view.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @sushmita

      Hi
      Then just call setModel on view with null pointer.
      It will then disconnect the model and show nothing.

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        @sushmita

        Hi
        Then just call setModel on view with null pointer.
        It will then disconnect the model and show nothing.

        S Offline
        S Offline
        sushmita
        wrote on last edited by
        #8

        @mrjj
        actually I am trying to display certain set of rows in table based on key entered and when I enter new key in textedit and push button it should display the rows related to entered key

        mrjjM 1 Reply Last reply
        0
        • S sushmita

          @mrjj
          actually I am trying to display certain set of rows in table based on key entered and when I enter new key in textedit and push button it should display the rows related to entered key

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #9

          @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
          3
          • S Offline
            S Offline
            sushmita
            wrote on last edited by sushmita
            #10

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #11

              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
              1
              • SGaistS SGaist

                Hi,

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

                S Offline
                S Offline
                sushmita
                wrote on last edited by
                #12

                @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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  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
                  1
                  • SGaistS SGaist

                    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.

                    S Offline
                    S Offline
                    sushmita
                    wrote on last edited by
                    #14

                    @SGaist said in PyQt reset tabelView:

                    QSortFilterProxyModel

                    I am not using QSortFilterProxyModel

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

                      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
                      1
                      • SGaistS SGaist

                        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.

                        S Offline
                        S Offline
                        sushmita
                        wrote on last edited by sushmita
                        #16

                        @SGaist

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

                        S 1 Reply Last reply
                        0
                        • S sushmita

                          @SGaist

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

                          S Offline
                          S Offline
                          sushmita
                          wrote on last edited by
                          #17

                          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
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            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
                            1

                            • Login

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