Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Clearing a QTtableview
Forum Updated to NodeBB v4.3 + New Features

Clearing a QTtableview

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 896 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    Hi All,
    I'm fairly new to QT but am having an issue with clearing QT table view. Basically I have two tables views, one filled with items that I can drag and drop to the second one. What I'd like to do is click on a clear button to erase the items from the second view.
    I've tried clear but that class function doesn't exist, I tried
    [code]
    QItemSelectionModel *mod2 = ui->tableView_2->selectionModel();

     while( mod2->model( )->rowCount( ) )
     {
        mod2->model()->removeRow( 0,  &mod2 );
     }
    

    [/code]

    I thought I could use removeRow, however I don't know what the second parameter should be or even if I did would it clear the box?
    Can anyone advise on this please? I think I'm talking myself in circles. Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by Sam
      #2

      You can easily do that by removing all rows from the model itself

      model()->removeRows(0, model()->rowCount());

      in your case it should be :

      ui->tableView_2->model()->removeRows(0,ui->tableView_2->model()->rowCount());

      1 Reply Last reply
      1
      • T Offline
        T Offline
        tony67
        wrote on last edited by
        #3

        Thanks. Worked a treat. Easy for some, tricky for me :)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          You are welcome, There is another function as clear() - Removes all items (including header items) from the model and sets the number of rows and columns to zero.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved