Results 1 to 5 of 5

Thread: Editable SqlQueryModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2014
    Posts
    14
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    8

    Default Editable SqlQueryModel

    Hello,
    I have a TableView that uses an SqlQueryModel. I want some of the cells in the table to be editable but the edits should not affect the original database. I subclassed SqlQueryModel with ItemFlags that allow it to be editiable. Because I do not want the changes to affect the database, I can't re implement the setData function, and so any edits get ignored as soon as I hit enter. Any ideas on how I can get the data entered in the view to stay there without affecting the model? Also, how can I tell the subclassed SqlQueryModel that I only want the cells in the second column that do not contain data to be editable?
    The following is my subclass:

    Qt Code:
    1. #include "editablesqlmodel.h"
    2. class EditableSQLModel;
    3.  
    4. EditableSQLModel::EditableSQLModel(QObject *parent):
    5. {
    6.  
    7. }
    8. Qt::ItemFlags EditableSQLModel::flags(const QModelIndex &index) const
    9. {
    10. Qt::ItemFlags flags = QSqlQueryModel::flags(index);
    11. if (index.column() == 1) flags |= Qt::ItemIsEditable;
    12. return flags;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Miss Engineer; 14th May 2014 at 11:37.

Similar Threads

  1. Replies: 1
    Last Post: 19th January 2014, 23:29
  2. Replies: 2
    Last Post: 1st May 2013, 06:49
  3. TableView + SqlQueryModel: can't insert or edit rows
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2008, 21:55
  4. editable rectangles
    By parmar ranjit in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2008, 09:59

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.