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. Any way a database model QTableView could have an extra "total" row?

Any way a database model QTableView could have an extra "total" row?

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 2.6k Views 4 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.
  • Christian EhrlicherC Christian Ehrlicher

    You did not say that you want to sort :)
    Then I would try it with a QIdentityProxyModel chained after the QSortFilterProxyModel.

    /edit: and even when you want to sort you can set the sort role to something else: https://doc.qt.io/qt-5/qsortfilterproxymodel.html#sortRole-prop

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #5

    @Christian-Ehrlicher
    I did not say lots of things!

    I have a well-established working set of tables/models/views. They do lots of things: sorting, filtering, editing, special display of values, .... Now I want an extra row at the bottom, sometimes, so I can display totals in certain numeric columns. Other columns in that row will be blank. The first column may well need to display a "Total" text, even if that column normally displays something else. I want everything to work just as it did, and then a total row as well.

    Oh, and btw: if the code sorts now, I don't expect to have to "set the sort role to something else" to make something work. I expect the addition of the total row not to require much changes to existing code (other than my calculating it from the model, obviously).

    :)

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      You did not say that you want to sort :)
      Then I would try it with a QIdentityProxyModel chained after the QSortFilterProxyModel.

      /edit: and even when you want to sort you can set the sort role to something else: https://doc.qt.io/qt-5/qsortfilterproxymodel.html#sortRole-prop

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #6

      @Christian-Ehrlicher
      The more I think about it, the more it seems to me what I really want is a "footer" like the header row, not as a row in the table, so I can put arbitrary text there like in the column headers. In my C# ASP.NET, tables had a (optional) footer as well as a header!

      I looked into this, and it seems that QTableViews have no option for a footer. The only way is to write a lot of code yourself, including fiddling with the QTableView's area to accommodate the footer, which is well beyond the scope for me here.

      1 Reply Last reply
      1
      • JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #7

        Since it can't be done, I ended up making do, in my particular case, with an extra row in the model, using a QStandardItemModel.

        Not happy, but needs-must! :)

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

          Hi,

          Maybe the Frozen Column example might give you some ideas.

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

          JonBJ 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Maybe the Frozen Column example might give you some ideas.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #9

            @SGaist
            And so it might, for others who read this. For me, at least in this situation, anything more than about half a dozen lines is deemed "too complex/too much effort"! Multiple views, viewports, scrollers etc. is way too much for my situation.

            Now, if Qt decides to add a (optional) footer to a QTableView in the way it has added a header, please let me know :)

            S 1 Reply Last reply
            0
            • JonBJ JonB

              @SGaist
              And so it might, for others who read this. For me, at least in this situation, anything more than about half a dozen lines is deemed "too complex/too much effort"! Multiple views, viewports, scrollers etc. is way too much for my situation.

              Now, if Qt decides to add a (optional) footer to a QTableView in the way it has added a header, please let me know :)

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

              Hi all,
              Sorry for necro-posting but I don't think it deserves new separate topic.
              Do I understand right that nothing have changed since 2019? I.e. we still have no good way to have a footer row in QTableView?

              Basically a dozen code lines is what I was looking for... but I feel myself ready to make some extra class if required... but... I'm not sure that there is any good option to implement it rather than onces discussed above in this topic.

              SGaistS 1 Reply Last reply
              0
              • S StarterKit

                Hi all,
                Sorry for necro-posting but I don't think it deserves new separate topic.
                Do I understand right that nothing have changed since 2019? I.e. we still have no good way to have a footer row in QTableView?

                Basically a dozen code lines is what I was looking for... but I feel myself ready to make some extra class if required... but... I'm not sure that there is any good option to implement it rather than onces discussed above in this topic.

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

                @StarterKit hi,

                It depends a bit on what you want to show and how.

                A proxy model could also be used.

                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

                  @StarterKit hi,

                  It depends a bit on what you want to show and how.

                  A proxy model could also be used.

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

                  @SGaist I need exactly the same as @JonB described.
                  I use a working application with tables/models/views and I need to add a footer to a couple of QTableViews that would be able to show total sum of this column.

                  JonBJ 1 Reply Last reply
                  0
                  • S StarterKit

                    @SGaist I need exactly the same as @JonB described.
                    I use a working application with tables/models/views and I need to add a footer to a couple of QTableViews that would be able to show total sum of this column.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #13

                    @StarterKit
                    I don't recall my exact situation or what I understood then, but knowing what I do now I only know there is just adding a (identity) proxy model appending one more row. It would have to come on top of any sort proxy. Certainly QTableView has not introduced a footer :)

                    S 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @StarterKit
                      I don't recall my exact situation or what I understood then, but knowing what I do now I only know there is just adding a (identity) proxy model appending one more row. It would have to come on top of any sort proxy. Certainly QTableView has not introduced a footer :)

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

                      @JonB ok, thank you for your comment, it is ok.
                      My idea might be a bit strange... but I managed to add one more QHeaderView below the table, it looks good.
                      So I subclassed it and created my own FooterView class to handle paintSection() event and provide data from the model with custom User-role.
                      I don't need fancy UI style and column movments so I think I'll survive with this solution :)

                      JonBJ 1 Reply Last reply
                      0
                      • S StarterKit

                        @JonB ok, thank you for your comment, it is ok.
                        My idea might be a bit strange... but I managed to add one more QHeaderView below the table, it looks good.
                        So I subclassed it and created my own FooterView class to handle paintSection() event and provide data from the model with custom User-role.
                        I don't need fancy UI style and column movments so I think I'll survive with this solution :)

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #15

                        @StarterKit
                        Sounds good. I think mine was very specifically wanting an extra row at the bottom of the table rows, as an extra row.

                        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