Results 1 to 10 of 10

Thread: removing row from QTableWidget, showing no effect

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: removing row from QTableWidget, showing no effect

    I used backword loop, removing items from last,
    As shown below
    Qt Code:
    1. int m=ui->tableWidget_ouput->rowCount();
    2. while(m>=NewRow)
    3. {
    4. ui->tableWidget_ouput->removeRow(m);
    5. m--;
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: removing row from QTableWidget, showing no effect

    Ehm, what about QTableWidget::clearContents() or QTableWidget::clear()?

    EDIT: Forget it, read too fast, didn't see NewRow...

  3. #3
    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: removing row from QTableWidget, showing no effect

    I went there too. Those functions remove the content from the table but leave the dimensions the same, i.e. rowCount() is unchanged. Contrast that with removeRow(), as used in the original post, which actually shrinks the table. I guess it really depends on what your application actually requires.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: removing row from QTableWidget, showing no effect

    Wouldn't this be the quickest?

    Qt Code:
    1. ui->tableWidget->setRowCount(NewRow);
    To copy to clipboard, switch view to plain text mode 

    I don't know what happens with those excessive items, if they are deleted or not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: removing row from QTableWidget, showing no effect

    Because I was curious:
    Qt Code:
    1. void QTableModel::setRowCount(int rows)
    2. {
    3. int rc = verticalHeaderItems.count();
    4. if (rows < 0 || rc == rows)
    5. return;
    6. if (rc < rows)
    7. insertRows(qMax(rc, 0), rows - rc);
    8. else
    9. removeRows(qMax(rows, 0), rc - rows);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Yes, they are!

Similar Threads

  1. Replies: 1
    Last Post: 5th May 2011, 09:37
  2. Removing pressed effect from a QPushButton
    By Luc4 in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2010, 11:43
  3. Removing Focus from QTableWidget
    By kapoorsudhish in forum Newbie
    Replies: 2
    Last Post: 22nd October 2009, 14:16
  4. Removing items from QtableWidget
    By algajard in forum Qt Programming
    Replies: 1
    Last Post: 17th March 2009, 09:31
  5. Removing a QWidget object from a QTableWidget cell
    By mclark in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2008, 15:19

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.