Results 1 to 3 of 3

Thread: Getting row number in Qtablewidget

  1. #1
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting row number in Qtablewidget

    Hi,

    I want to find the way to get the multiple selected row numbers (ex: 2nd and 3rd rows) in a table instead of how many rows are selected. Can any one please tell me the way.

    Thank You,
    Baluk
    Last edited by baluk; 28th September 2010 at 16:23.

  2. #2
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting row number in Qtablewidget

    Qt Code:
    1. for(short s=0; s < table->rowCount(); s++)
    2. {
    3. if(table->item(s,0)->isSelected())
    4. {
    5. qDebug()<<"Row "<<s<<"is selected!";
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    this would work, but there are better ways i think

  3. #3
    Join Date
    Jun 2010
    Posts
    137
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting row number in Qtablewidget

    Thnaks man. I got the other way around this problem. It works very fine.

    Qt Code:
    1. QItemSelectionModel* selectionModel = ui->tableWidget->selectionModel();
    2.  
    3. QModelIndexList selected = selectionModel->selectedRows();
    4.  
    5. for(int i= 0; i< selected.count();i++)
    6. {
    7. QModelIndex index = selected.at(i);
    8. qDebug() << index.row();
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    I got the code from one of the old posts in this forum.

Similar Threads

  1. Qt and number crunching
    By The_Fallen in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2010, 20:49
  2. Replies: 2
    Last Post: 17th November 2009, 16:14
  3. How to get row number from tableView
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 26th March 2009, 16:30
  4. Number of folder
    By Benjamin in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2008, 10:33
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

Tags for this Thread

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.