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. [solved] QT add custom table view
Forum Updated to NodeBB v4.3 + New Features

[solved] QT add custom table view

Scheduled Pinned Locked Moved General and Desktop
tableviewmodel
7 Posts 2 Posters 1.9k Views 2 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
    sachi
    wrote on last edited by sachi
    #1

    I am working on application that used QSqlTableModel and tableview. my model contain columns quantity and unit price. now i want to show in tableview column named amount that is equal to quantity X unit price. is there any way to it using custom delegates or any otherway? and also when i add new row to table it should automatically fill amount column.

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

      Hi,

      You can use a proxy model which will return on additional column, in the data function you'll reimplement, return the amount like you want.

      You control the row adding part, so it's up to you to fill the values you want in.

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

        hi Thank you for your solution. I am new to qt and programming. I have looked for examples which subclass proxymodel but i could not find anything. can you show me how to subclass proxymodel. and also is their any possibility to use proxy model to join two qsqltablemodel?

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

          Hi,

          QSortFilterProxyModel and QIdentityProxyModel are two good examples of proxy models.

          Two QSqlTableModel ? You would need a model on top of them that would return the columnCount that is the sum of both table column count and map the index in setData/data to the right QSqlTableModel

          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
          • S Offline
            S Offline
            sachi
            wrote on last edited by
            #5

            Thank you. Is there any good tutorials for this? I couldn't found any good tutorials. i am new to qt.

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

              The "Custom Sort/Filter Model Example" filter example in Qt's documentation comes to mind

              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
              • S Offline
                S Offline
                sachi
                wrote on last edited by
                #7

                Thank you for your help. I will look in to it.

                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