Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QAbstractTableModel
Forum Updated to NodeBB v4.3 + New Features

QAbstractTableModel

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 454 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.
  • N Offline
    N Offline
    Nightmaster
    wrote on 3 Sept 2024, 19:01 last edited by
    #1

    Hello

    I have used QAbstractTableModel to display some data in a QTableView and it works fine.

    I just don't understand how the data method works and its really annoying me.

     def data(self, QModelIndex, role= QtCore.Qt.DisplayRole):
    
    It seems to me like there should be a loop that goes through each QModelIndex row and QModelIndex column but in this method only one line is needed. to do this. Is this what is happening under the hood?
    
            if role == QtCore.Qt.DisplayRole:
    
                try:
    
                    return self.data[QModelIndex.row()][QModelIndex.column()]
    
                except IndexError:
    
                    return ""
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Sept 2024, 19:32 last edited by
      #2

      Hi,

      The index parameter gives you the positional information: row and column.
      The role gives you which type of data is expected to get returned. If covers the data itself but also hints about how it should be rendered such as foreground and background color, associated decoration etc. That the delegate can use to do its work.

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

      N 1 Reply Last reply 3 Sept 2024, 19:41
      1
      • S SGaist
        3 Sept 2024, 19:32

        Hi,

        The index parameter gives you the positional information: row and column.
        The role gives you which type of data is expected to get returned. If covers the data itself but also hints about how it should be rendered such as foreground and background color, associated decoration etc. That the delegate can use to do its work.

        N Offline
        N Offline
        Nightmaster
        wrote on 3 Sept 2024, 19:41 last edited by
        #3

        @SGaist Thanks for explaining but isn't there a loop going on to fill each row and column with the data?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Sept 2024, 19:44 last edited by
          #4

          The view(s) will request the data as required.

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

          N 1 Reply Last reply 3 Sept 2024, 19:46
          1
          • S SGaist
            3 Sept 2024, 19:44

            The view(s) will request the data as required.

            N Offline
            N Offline
            Nightmaster
            wrote on 3 Sept 2024, 19:46 last edited by
            #5

            @SGaist Ahh ok yes i think i get it now.

            Thank you

            1 Reply Last reply
            0
            • N Nightmaster has marked this topic as solved on 3 Sept 2024, 19:47

            1/5

            3 Sept 2024, 19:01

            • Login

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