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. How to get set model correctly

How to get set model correctly

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.7k 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.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    Hello people!

    I have a QAbstractTableModel class, a delegate class, QListView and QTable view.
    in the model class (which inherits the QAbstractTableModel) I have a Qlist of data object.
    in the delegate class I paint it for the view, so in the view part I do the following
    listView->setmodel(model);
    tableView->setModel(model);

    listView->setItemDelegate(delegate);
    tableView->setItemDelegate(delegate);

    and the output for the list View is exactly what I want, rows painted by the delegates, but for the table view I have the same number of row as in the list and the columns also but all items in a row has the same value, I don't guess why
    can you answer me please?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Sounds like a problem in the data() implementation of your model.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tokafr
        wrote on last edited by
        #3

        I think the problem is the columnCount() and rowCount()
        my rowCount returns dataList.size(); and it's ok for list view but for table view it is extra rows and how can I fix it?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Eh? You only want to show a subset of the data that is visible in the table view in the list view? That is: the list should have fewer rows than the table?

          If so, you cannot use the (exact) same model. You might be able to use a proxy model to filer your base model back to the rows you want to show in the list though.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tokafr
            wrote on last edited by
            #5

            So I cannot use tableModel for both list and table view?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Of course you can!

              You just can't expect the same model to have a different number of rows for two different views.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tokafr
                wrote on last edited by
                #7

                Aaah, ok thank you

                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