Results 1 to 2 of 2

Thread: problem removing selected rows from QTableWidget

  1. #1
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem removing selected rows from QTableWidget

    I want to remove selected rows from QTableWidget..When i click on the button,if i have,for example three selected items only 2 are deleted.
    Why this occurs?
    This is my code:

    QList <QTableWidgetItem *> items = ui->tableWidget->selectedItems();

    for (int x=0;x<ui->tableWidget->rowCount();x++)
    {
    if(items.at(x)->isSelected())
    ui->tableWidget->removeRow(x);
    }

  2. #2
    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: problem removing selected rows from QTableWidget

    The first time you remove a row subsequent row numbers change. For example, remove row 2 and row 3 becomes the new row 2, you then increment x and look at row 3. The original row 3 never gets looked at.

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

    milli (5th May 2011)

Similar Threads

  1. Replies: 4
    Last Post: 6th March 2011, 09:54
  2. Selected Rows moveUp/moveDown in QTableWidget
    By imagineryhead in forum Qt Programming
    Replies: 12
    Last Post: 14th September 2010, 15:01
  3. removing of selected rows
    By MrShahi in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2008, 15:05
  4. Removing rows
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 16:54
  5. Replies: 5
    Last Post: 2nd April 2007, 08:57

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.