Results 1 to 2 of 2

Thread: Select row in QTableView after insert.

  1. #1
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11 Windows

    Default Select row in QTableView after insert.

    Hello,

    I would like to select a row in the a tableview after inserting it. I'm inserting the row as the last in the model, using QSqlTableModel.insertRow(QSqlTableModel.rowCount() ). I want to select the inserted row in a QTableView which uses this model.
    My problem is I cannot find which row in the table view corresponds to the new row in the model. Or, in other words: given a row in the model, how can I know the row where it's displayed in the table?

    Thanks !
    Last edited by fede; 14th April 2009 at 02:02. Reason: Added text

  2. #2
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Select row in QTableView after insert.

    Sorry... should have looked around further: the answer is here

    Qt Code:
    1. QModelIndex i; // ?
    2. table->selectionModel()->select(i, QItemSelectionModel::Select);
    To copy to clipboard, switch view to plain text mode 

    Since I also have a QSortFilterProxyModel between the model and the view, I had to use QSortFilterProxyModel.mapFromSource to convert the model index to the filter proxy's index (the table view has the filter proxy set as it's model).

Similar Threads

  1. QSqlTableModel and QTableView selection problems
    By innerhippy in forum Qt Programming
    Replies: 5
    Last Post: 19th December 2008, 05:48
  2. How to select a cell in a QTableView
    By JeanC in forum Qt Programming
    Replies: 6
    Last Post: 6th February 2008, 13:20
  3. Bulk insert into SQLite
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2007, 03:56
  4. Insert QCheckBox into QTableView
    By wind in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2006, 16:15
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.