Results 1 to 1 of 1

Thread: Maintaining QTableView Selection through submitAll()

  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Question Maintaining QTableView Selection through submitAll()

    G'day All

    I have a QTableView displaying data from a QSqlTableModel derivative. The user can select a row in the view and open a dialog to edit the details. When the user opts to commit the changes in the dialog, submitAll() is called as the dialog is closed. This action clears the table view selection. I'd like to keep the edited row selected but I'm having trouble doing so. (When the user cancels the dialog, revertAll() is used to discard any changes, and the selection remains valid.)

    I initially tried the lightly documented QPersistentIndex to find that they are not valid after the submitAll() and consequently not very useful. In http://www.qtcentre.org/forum/f-qt-p...ght=persistent Wysota suggests storing the primary key of the row (which I can do) and re-selecting it after the submitAll(). How do I achieve this? The only way I can see is iterating over the model to find the row with the same primary key, something that strikes me as not very efficient.

    I'd like to do something similar with deleting rows, leaving the row above or below selected afterward, and adding rows where the new row is selected afterward. For deleting the stored primary key approach will work. For adding rows, I don't have a primary key to store. How do I tackle it then?

    Any thought appreciated,
    Chris W
    Last edited by ChrisW67; 27th July 2009 at 01:01. Reason: Better title

Similar Threads

  1. Replies: 5
    Last Post: 24th July 2009, 22:30
  2. Replies: 2
    Last Post: 7th June 2009, 10:47
  3. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  4. Index (position) changed on saving with QTableView
    By Auryn in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2008, 08:15
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.