Results 1 to 9 of 9

Thread: QTtableView how to display aggregate in the bottom

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTtableView how to display aggregate in the bottom

    What could I be missing?
    I am guessing that your proxy model is relying on the source model for the row count - does your override of rowCount() ever get called?

    Have you also overridden the QSortFilterProxyModel::filterAcceptsRow() protected method?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    Dec 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTtableView how to display aggregate in the bottom

    Quote Originally Posted by d_stranz View Post
    ...does your override of rowCount() ever get called?
    Yes, it gets called properly. I modified my override to confirm:

    Qt Code:
    1. int DecoratorProxyModel::rowCount(const QModelIndex &parent) const
    2. {
    3. qDebug() << "proxy rowCount() call, sourceModel():" << sourceModel()->rowCount(parent) << "base class rowCount():" << QSortFilterProxyModel::rowCount(parent);
    4. qDebug() << "modified rowCount() response:" << sourceModel()->rowCount(parent) + 1;
    5. return sourceModel()->rowCount(parent) + 1;
    6. // return QSortFilterProxyModel::rowCount(parent) + 1;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Both implementations, using the source model rowCount() and using the base class rowCount() report the same number of rows.

    Debug output:
    Qt Code:
    1. > Source model initModel(), rows: 7
    2. proxy rowCount() call, sourceModel()->rowC: 7 base class rowCount(): 7
    3. modified rowCount() response: 8
    4. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    5. modified rowCount() response: 8
    6. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    7. modified rowCount() response: 8
    8. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    9. modified rowCount() response: 8
    10. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    11. modified rowCount() response: 8
    12. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    13. modified rowCount() response: 8
    14. proxy rowCount() call, sourceModel(): 7 base class rowCount(): 7
    15. modified rowCount() response: 8
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by d_stranz View Post
    Have you also overridden the QSortFilterProxyModel::filterAcceptsRow() protected method?
    No, I didn't touch the QSortFilterProxyModel::filterAcceptsRow() method. In fact, I've read Qt docs and found out that it is better to use QIdentityProxyModel if I just want to modify the output. So, I tried subclassing identity proxy overriding only rowCount() and data() methods with the same code I did for sortfilter proxy, but it didn't help, the view doesn't call the data() method for that additional virtual rowCount()+1 row.

    I also tried fiddling with the QSortFilterProxyModel::flags(), but seems like it doesn't get called for the virtual row either.
    Qt Code:
    1. Qt::ItemFlags DecoratorProxyModel::flags(const QModelIndex &index) const
    2. {
    3. qint32 row = index.row();
    4. qint32 col = index.column();
    5. qDebug() << "flags():" << row << col;
    6. return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
    7. }
    To copy to clipboard, switch view to plain text mode 

    And I thought I understood how Qt's Model View framework works :-)

Similar Threads

  1. QtTableView update
    By cpuinthebrain in forum Qt Programming
    Replies: 0
    Last Post: 24th June 2015, 20:35
  2. Group / Aggregate QAbstractItemModel
    By Nightfox in forum Qt Programming
    Replies: 11
    Last Post: 10th January 2010, 19:09
  3. Replies: 6
    Last Post: 9th January 2008, 15:56
  4. Replies: 7
    Last Post: 15th November 2007, 17:19
  5. Replies: 5
    Last Post: 29th January 2006, 17:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.