Results 1 to 2 of 2

Thread: Removing items from QtableWidget

  1. #1
    Join Date
    Mar 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Removing items from QtableWidget

    Hey kids,

    I'm using Qt-4.5 with Qt-Creator running under linux and I have the following problem. I have a QTableWidget with "n" rows. Then I select "m" rows for deletion. My problem is that the method only deletes "m-1" rows from the table.

    QList<QTableWidgetSelectionRange> range=tipos_table->selectedRanges();

    for(i=0;i<range.size();i++)
    {
    top=range.at(i).topRow();
    bottom=range.at(i).bottomRow();
    for(j=top;j<=bottom;j++)
    tipos_table->removeRow(j);
    }

    That is the method I wrote. The method visits all the items but the last item will not be deleted.

    Clues, ideas ?

    Regards and thanks,

  2. #2
    Join Date
    Mar 2009
    Location
    Leiden, The Netherlands
    Posts
    10
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Removing items from QtableWidget

    30-years old kid responding

    Have you tried to remove the rows in reverse order? I can imagine when you start removing the rows from the top, the rows further down on are shifted upwards, thus not matching the initial rowcount you queried using selectedRanges().

    I suggest reversing both the list iteration (variable i) as well as the row removal code (variable j)

Similar Threads

  1. QTableWidget: set items disappear after new insertion
    By Raccoon29 in forum Qt Programming
    Replies: 6
    Last Post: 16th March 2008, 18:28
  2. removing model Items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 25th November 2007, 20:10
  3. How to update scene after removing items
    By nileshsince1980 in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 09:56
  4. adding items in qtablewidget
    By Djony in forum Qt Programming
    Replies: 17
    Last Post: 24th November 2006, 10:03
  5. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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.