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. Questions about QAbstractTableModel and QSortFilterProxyModel usage
Qt 6.11 is out! See what's new in the release blog

Questions about QAbstractTableModel and QSortFilterProxyModel usage

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k 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
    SvenA
    wrote on last edited by
    #1

    Hello!

    I'm new to the model/view system and I'm trying to implement a data entity list
    using it. I have two list (a local and a global one), which I want to be shown merged
    in one list. This list should show a list of all available data entities of
    these two list (in particular only the name) and if I double click on it, a new
    dialog pops up, where I can edit the entity's data.

    Because this list can be long, I wanted it sorted and (optional) filtered. So I
    used a proxy model.

    You can find the example source code under:

    "http://pastebin.com/Z0YKmc99":http://pastebin.com/Z0YKmc99

    Now my questions:

    Is it the right way to implement this, as I done it?

    Or is there a better way?
    (Maybe I doing it fundamentally wrong?!)
    

    In my code I cannot select the sorting order. I used

      _proxyModel->sort(1, Qt::AscendingOrder);_
    on the newly created proxyModel in my code, but it's
    always ordered descending. Why?
    

    If I add or change an entry, the list is not reordered. If I use

    reset(), I will loose the selection. What's wrong here?
    

    If I delete an entry, I call "beginResetModel()" and "endResetModel()".

    Is there a better way to force a correct update of the list?
    

    Any answers or hints welcome...

    Regards
    Sven

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SvenA
      wrote on last edited by
      #2

      Does nobody have any hints or answers?

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        Just a quick look at your code, but for option 4:
        There are also "beginRemoveRows(const QModelIndex &, int, int)" and thus with the index you only have the view update the selected rows. The same goes for columns.
        When you have an editable model you should not use the dynamicsort option (read the doc!), but rather use the sort function!
        Sorry, no more time to go into depth!

        Greetz, Jeroen

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SvenA
          wrote on last edited by
          #4

          [quote author="Jeroentje@home" date="1404981797"]
          JWhen you have an editable model you should not use the dynamicsort option (read the doc!), but rather use the sort function!
          Sorry, no more time to go into depth![/quote]

          Hmmm...
          I thought this only applies, if I edit the data in the list/table itself.

          The documentation states the following:

          bq. By default, the model dynamically re-sorts and re-filters data whenever the original model changes. This behavior can be changed by setting the dynamicSortFilter property.

          Because I changed the data in the model, I thought this would be propagated upwards. But how should the ListModel (QAbstractTableModel) know about the change? Therefore I tried to use "emit model->dataChanged(...)" but I did not work either.

          How do I signal the ListModel (& ProxyModel), that the underlying data has changed?

          At this point I think I made something fudamentally wrong...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SvenA
            wrote on last edited by
            #5

            [quote author="Jeroentje@home" date="1404981797"]Hi,
            Just a quick look at your code, but for option 4:
            There are also "beginRemoveRows(const QModelIndex &, int, int)" and thus with the index you only have the view update the selected rows. The same goes for columns.
            [/quote]

            You'll find that in my code too (line 140 in main.c). I commented it out, because it did not work. If it should work, what I'm doing wrong here?

            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