Results 1 to 5 of 5

Thread: Getting the selected row

  1. #1
    Join Date
    Feb 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Getting the selected row

    Hi there folks!

    I know that to remove a given record from a model, I would need to provide the record to remove. The problem is that the record to be removed is one selected by the user in a table view (obviously linked to the model).

    How would I obtain an integer for the row number, that can be used in the following way:

    Qt Code:
    1. model->removeRows(int row, int count)
    To copy to clipboard, switch view to plain text mode 

    As usual sample code and an explanation would be very much appreciated.

    Thanks in advance,

  2. #2
    Join Date
    Feb 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Getting the selected row

    BUMP please

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Getting the selected row

    J-P Nurmi

  4. #4
    Join Date
    May 2009
    Posts
    28
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting the selected row

    QTableView gives you the selected row(s) :

    Qt Code:
    1. QModelIndexList list = view->selectionModel()->selectedRows();
    2. int row = list.at(i).row();// i = integer to browse list
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to QAmazigh for this useful post:

    waynew (18th March 2010)

  6. #5
    Join Date
    Apr 2009
    Posts
    21
    Thanked 3 Times in 2 Posts

    Default Re: Getting the selected row

    And... there is a signal to notify you the cell just selected by user:

    Qt Code:
    1. void QAbstractItemView::activated( const QModelIndex & index )
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 12:49
  2. Highlighting selected section on QDateTimeEdit
    By Yorma in forum Qt Programming
    Replies: 4
    Last Post: 3rd May 2013, 12:03
  3. How to get parent of selected item in TreeView?
    By RavenS in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2009, 13:27
  4. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 07:53
  5. Zooming a paricular selected region
    By Kapil in forum Newbie
    Replies: 8
    Last Post: 9th May 2006, 14:41

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.