Results 1 to 1 of 1

Thread: QTableView rows correctly hidden until scroll

  1. #1
    Join Date
    Nov 2015
    Location
    Vermont
    Posts
    52
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QTableView rows correctly hidden until scroll

    I have two QTableViews that share a QSqlQueryModel set as their model. I have deliberately hidden some rows in each, based on the value of a column in the QSqlQueryModel, as in the example as follows:

    Qt Code:
    1. for (int i = 0; i < model->rowCount(); i++) {
    2. bool assigned = model->record(i).value(0).toBool();
    3. if (assigned) {
    4. // Hide from available options
    5. ui->available_tableview->setRowHidden(i, true);
    6. } else {
    7. // Hide from assigned list
    8. ui->assigned_tableview->setRowHidden(i, true);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    This all works fine, until I scroll either table (they are in the same MainWindow) and then all of the rows that are hidden in the assigned_tableview show up again. Oddly, the rows that are hidden in the available_tableview stay hidden. I have tried using two different models, and they same behavior occurred. I also tried emitting layoutChanged() from the model, as recommended by this answer, but the behavior remained. Any ideas on what might be causing this behavior?


    Added after 1 41 minutes:


    Okay, so on my drive home I think I realized what the issue is. The QSqlQueryModel is only loading the first 256 results by default, so when I scroll it loads more. I'm not actually seeing rows that I have hidden reappear, I am seeing rows that weren't previously loaded appear. If I fetch all the results before setting the model, this issue *should* go away. I have to wait until I'm back at my work machine tomorrow to confirm, but I wanted to post this here so people didn't waste time answer a question that I think I have an answer to. Couldn't figure out how to delete the question!
    Last edited by ce_nort; 3rd December 2023 at 00:10.

Similar Threads

  1. QTableView, glitch on showing hidden rows
    By JuicyPussy in forum Qt Programming
    Replies: 0
    Last Post: 24th July 2020, 01:24
  2. QTableView Hidden Sections and Indexes
    By mechsin in forum Newbie
    Replies: 1
    Last Post: 15th July 2012, 18:49
  3. Showing a Hidden QTableView Column
    By dchow in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2011, 01:11
  4. QTableWidget sorting with hidden rows
    By alex140773 in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2008, 13:35
  5. Replies: 1
    Last Post: 28th September 2006, 07:21

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.