Results 1 to 10 of 10

Thread: Deleting selected row from a QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Deleting selected row from a QTableView

    Line 4 creates a new selection model rather than fetching the model that is already associated with the view. Line 5 does not do what you think it does: it deselects everything, it does not delete selected data. You want something like this (I haven't tested it so please forgive minor glitches):
    Qt Code:
    1. void Loader::removeChannelFromTable()
    2. {
    3. QMessageBox::information(this,tr(""),tr("Slot working?") ); // to make sure slot is being run.
    4.  
    5. // code to get list of selected rows
    6. QItemSelectionModel *selected = channelsView->selectionModel();
    7. QModelIndexList rowList = selected->selectedRows();
    8.  
    9. // code to delete these model indexes from the model
    10. foreach(QModelIndex rowIndex, rowList) {
    11. model->removeRow(roxIndex.row(), rowIndex.parent());
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    You might also consider using QAbstractItemView::setSelectionBehavior() and QAbstractItemView::setSelectionMode() on the view so the user selects whole rows etc.

  2. The following user says thank you to ChrisW67 for this useful post:

    Ferric (14th January 2010)

Similar Threads

  1. QTableView get selected row
    By raphaelf in forum Qt Programming
    Replies: 8
    Last Post: 12th July 2013, 03:35
  2. Deleting QSqlTableModel and QTableView
    By waynew in forum Qt Programming
    Replies: 7
    Last Post: 24th December 2009, 00:17
  3. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 07:53
  4. iterating selected rows in a qtableview
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2008, 14:29
  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.