Results 1 to 2 of 2

Thread: Edit Control on a TableView

  1. #1
    Join Date
    Jul 2015
    Posts
    9
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Edit Control on a TableView

    I have attached a pic to illustrate my problems. I would love to manage some behind the scene activities when the user selects an option on the last row (actually its a new blank row inserted whenever the "Number" field of the previous row is updated with a number. It is inserted by a trigger on my Sqlite db) . The delete Column is the last column..its intended to delete the line when the user clicks on the IndexWidget, however, in some instances, the deletion is carried out on the wrong row I would like help here too.

    I have written a function for this as shown below has worked once and never again:

    Qt Code:
    1. void clsList::addSbj()
    2. {
    3. if (sbjmodel->isDirty()){
    4. int clInd = sbjmodel->fieldIndex("csNo");
    5. int sbjInd = sbjmodel->fieldIndex("subj");
    6. int clNo = 0;
    7. QSqlQuery qry;
    8. qry.exec("SELECT MAX(csNo)FROM setCls_Sbj");
    9. while (qry.next())clNo = qry.value(0).toInt()+1;
    10. int nwrow = ui->sbjV->currentIndex().row();
    11.  
    12. if (nwrow == sbjProxy->rowCount()-1)
    13. {
    14. QString sb(sbjProxy->index(nwrow,sbjInd).data().toString());
    15. if (sb == "<SELECT>")return;
    16. QModelIndex index = sbjProxy->index(nwrow,clInd);
    17. sbjProxy->setData(index,clNo);
    18. qDebug()<<clNo;
    19. sbjmodel->submitAll();
    20. sbjmodel->select();
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    This is not working out! Thank you!

    clsSbj.png.

  2. #2
    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

    Default Re: Edit Control on a TableView

    What is "not working out" about it?
    What event triggers the addSbj() function?

    We cannot see your delete logic. However, you are using a proxy on the model so the row number given by the proxy may not be the same as the row number of the underlying model. If you delete through the underlying model be careful you are using the row number from the right model.

Similar Threads

  1. Replies: 1
    Last Post: 14th October 2013, 08:07
  2. Replies: 2
    Last Post: 28th April 2011, 14:48
  3. Edit TableView Content
    By emorgen in forum Newbie
    Replies: 7
    Last Post: 2nd June 2010, 23:00
  4. TableView + SqlQueryModel: can't insert or edit rows
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2008, 22:55
  5. Rich edit control
    By Sparhawk in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2008, 12:15

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.