Hiding rows in QTableView seems to be slow



  • Hi,

    I am using QTableView for handling a table with up to 600,000 rows. Displaying the table and sorting it works well.
    However, in my interactive environment, I need to rapidly hide/show rows depending on the row index. For a smaller
    number of rows (~3000) this works perfectly fast but for 600,000 rows it is terribly slow. As a solution, I tried:
    @
    qtableview->setUpdatesEnabled(false);
    <showRow(...)/hide row(...)>
    qtableview->setUpdatesEnabled(true);
    @
    However, this didn't help.

    Any other idea is deeply appreciated.

    Best Regards,
    Steffen

    Edit: Please use @ tags to highlight code; Andre


  • Moderators

    Have a look at Qsortfilterproxymodel.



  • Thank you very much for the quick reply. I had a look at Qsortfilterproxymodel. I understand now how to use regular expressions to filter rows with respect to the contents of (a) specific field(s). However, I want to filter the rows with respect to their index which is not stored in any field. It just exists implicitly. For example, hide rows 1-5, 10-100, and 500-2000 and show the rest. Could you please provide a hint on how to use Qsortfilterproxymodel for that purpose.

    Thank you very much.
    Steffen




  • Moderators

    Your index is just a column in your table ,you should be able to filter on using filteracceptsrow.



  • Thanks for the helpful suggestions. I guess, I derive my own class from Qsortfilterproxymodel. Then, I overwrite the method filteracceptsrow. In my method, I check whether "int source_row" shall be shown or hidden based on a boolean array (size = number of rows) I already have and I return true or false, respectively. Once the boolean array in my interactive application changes, I have to call invalidateFilter() on my QSortFilterProxyModel. Am I right?

    Steffen



  • Yes, you are.



  • The procedure I described above works very well. Thanks a lot to Eddy and loladiro. Just one thing I would like to add is that instead of calling "invalidateFilter()" on the custom QSortFilterProxyModel, one should call "invalidate()" which is considerably faster. I don't know why...

    Steffen


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.