Results 1 to 7 of 7

Thread: Locating QTableView row

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Locating QTableView row

    I want to auto scroll to the row in a table view when the database contents of the row are known. The question is, how to link the database/model row to the view row.

    scrollTo() might work ok, if I could identify the table index value from the known database row.
    But I can't see how to do that.

    Any ideas?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Locating QTableView row

    You could also try if QAbstractItemView::scrollToBottom works for you.
    How are you adding data from database ? Is it model or what ??

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Locating QTableView row

    Data is already in the database. Yes, there is a model and a view.
    When the user enters a field and clicks a button in the mainwindow, the slot function finds the correct database record. Then it would be nice to have the view scroll to that record.
    The question is, knowing the correct database record, how to find it by index in the view?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Locating QTableView row

    Dont you have the index from the model ?? Same will be used for view

  5. #5
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Locating QTableView row

    That would be the thing... If I had it.

    From the doc, it looks like this would work:

    Qt Code:
    1. QModelIndex idx = model->indexInQuery(const QModelIndex & item);
    2. view->selectRow(idx);
    To copy to clipboard, switch view to plain text mode 

    But I don't understand what the item is. How does this relate to the record data?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Locating QTableView row

    Did you come across QAbstractItemModel::index ?
    When the user enters a field and clicks a button in the mainwindow, the slot function finds the correct database record
    Can you show the relevant code how you find the record from the model ? Because cant tell exactly without knowing what you are doing,, Let us know how you are using the model, how you are finding the item.

  7. #7
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    82
    Thanked 11 Times in 11 Posts

    Default Re: Locating QTableView row

    Thanks for your help. I got it working by selecting the id value (primary key) from the desired row, then

    Qt Code:
    1. view->selectRow(id-1);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 26th November 2009, 05:45
  2. Help QTableView
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 22nd November 2009, 01:44
  3. Locating a driver on the operating system
    By schall_l in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2008, 10:19
  4. QTreeWidget - locating items in viewport
    By kemp in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2007, 16:18
  5. QTableView - Add Row
    By maxpower in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 19:18

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.