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. Is it possible to filter model by value in Primary Key column?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to filter model by value in Primary Key column?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 2.9k 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.
  • S Offline
    S Offline
    SergeyK12
    wrote on last edited by
    #4

    By reading documentation more and more, i mention that this methods

    filterAcceptsColumn()
    filterAcceptsRow()

    used for filter current row or column.

    But, why there is no method like setFilterRegExp for other standart classes (int, bool for example)
    I just need to get a single row in my proxy model which contain in its Primary Key id column the value i specifyed.
    (It's easy with QString but difficult with int WTF)

    I't so dissapointing to reimplement everything in Qt for every simple task. And, yeah, i don't anderstand the way it working.

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

      The first parameter is the source model row you are going to inspect. The second is the parent item, usually only avoid when implementing a tree model.

      No, you shouldn't modify anything in the source model from that function. Just return whether the row passed as parameter should be returned for the filtering you want to do.

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

        The first parameter is the source model row you are going to inspect. The second is the parent item, usually only avoid when implementing a tree model.

        No, you shouldn't modify anything in the source model from that function. Just return whether the row passed as parameter should be returned for the filtering you want to do.

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

        @SGaist
        But how should i specify id i searching for?
        What if i didn't try to implement tree model. I only need to obtain a QSortProxyModel with a singl row (in source model more than 100 rows), which i put in QTableView. (with transpose row and columns)

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

          Like in the example, you add your own setter function for that.

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

            Like in the example, you add your own setter function for that.

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

            @SGaist
            I got it. I dont need to call this method by myself . QTableView will call it.
            And i only need to add new private varible with its setter wich i (variable) allow to use in filterAcceptsColumn().
            And when this method return true, QTableView will show me the instance ?
            And thats mean i shoul go along this row or column, and compare cell value with my specifyed id.
            ANd more, i dont eed to do any cicle by myself because QTableView will call this method in a cycle and give me const QModelIndex &source_parent which value i could compare.

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

              Yes, that's that.

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

                Yes, that's that.

                S Offline
                S Offline
                SergeyK12
                wrote on last edited by
                #10

                @SGaist
                It is worked well. Finally, after a day, it makes sense.

                Thank you very much! I do not know that I have done without your help!

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

                  You're welcome !

                  Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                  Note, you may have to first click on "Ask as question" before you can mark it solved.

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

                    You're welcome !

                    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                    Note, you may have to first click on "Ask as question" before you can mark it solved.

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

                    @SGaist
                    Done

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

                      Thanks !

                      Happy coding :)

                      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
                      0

                      • Login

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