Results 1 to 5 of 5

Thread: Remove selected rows from a QTableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Location
    Russia
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Lightbulb Re: Remove selected rows from a QTableView

    My code im using
    Qt Code:
    1. QModelIndexList indexes = ui->tableUserVars->selectionModel()->selectedRows();
    2. int countRow = indexes.count();
    3.  
    4. for( int i = countRow; i > 0; i--)
    5. modelUserVars->removeRow( indexes.at(i-1).row(), QModelIndex());
    To copy to clipboard, switch view to plain text mode 


    And if you are working with a large number of rows ( > 100,000 ) and the selection of lines in order not to sample the rapid removal of this way + if the selection is selectively remove the row from selectionModel

    My code im using fast delete rows > 1000000
    Qt Code:
    1. QModelIndexList indexes = ui->tableUserVars->selectionModel()->selectedRows();
    2. int countRow = indexes.count();
    3.  
    4. bool flagDif = false;
    5. for( int i = countRow; i > 1; i--)
    6. if (indexes.at(i-1).row()-1 != indexes.at(i-2).row())
    7. flagDif = true;
    8.  
    9. if (!flagDif)
    10. modelUserVars->removeRows(indexes.at(0).row(),countRow,QModelIndex());
    11. else
    12. for( int i = countRow; i > 0; i--)
    13. modelUserVars->removeRow( indexes.at(i-1).row(), QModelIndex());
    To copy to clipboard, switch view to plain text mode 

    Ps. Sorry bad englsh.
    Last edited by yarovenkoas; 2nd March 2016 at 08:03.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,332
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    317
    Thanked 871 Times in 858 Posts

    Default Re: Remove selected rows from a QTableView

    And why are you posting this in response to a 10 year old thread???

  3. #3
    Join Date
    Mar 2016
    Location
    Russia
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Remove selected rows from a QTableView

    maybe someone will come in handy =)

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView get selected row
    By raphaelf in forum Qt Programming
    Replies: 8
    Last Post: 12th July 2013, 03:35
  3. Copying QTableView rows
    By derrickbj in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 00:00
  4. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55
  5. Get list of selected rows from QTableView
    By jnk5y in forum Qt Programming
    Replies: 8
    Last Post: 17th February 2006, 16:59

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
  •  
Qt is a trademark of The Qt Company.