In most database applications that I've seen, the widget that displays the table data has an extra (blank) row at the bottom that the user can use to insert/append a new record into the database.
How can I do that with a QTableView?
In most database applications that I've seen, the widget that displays the table data has an extra (blank) row at the bottom that the user can use to insert/append a new record into the database.
How can I do that with a QTableView?
What did you already try?
I haven't tried anything... I don't know what to try, that's why I'm asking.
- Gordon E.
One option could be to subclass one of QSqlXxxModels, fake an extra row by reimplementing rowCount() and setting index widgets or opening persistent editors at the bottom row. Depending on types of editors, you could for example connect to QLineEdit::returnPressed() and insert the row on demand.
J-P Nurmi
In my opinion you don't really need to do anything - all that is needed is to call insertRow() on the model and edit the row (either automatically or letting the user start the editor). That's why I asked the question in the first place.
grellsworth (5th July 2007)
OK, I've tried adding a new row into my model, this looks like it might work. I'll let you know. I'm just concerned that after a new row is inserted, that a new blank line will appear.
Thank you for your help. I'll keep you posted on how it's going.
Sincerely,
Gordon E.
===== UPDATE =====
Here's what I'm doing right now:
Qt Code:
{ model->insertRow(model->rowCount()); }To copy to clipboard, switch view to plain text mode
This works fine for adding the initial empty row at the bottom of the table, but now I have to find a way to make sure that when the user successfully enters a new record, a new empty row will be added at the end.
Suggestions?
Sincerely,
Gordon E.
Last edited by grellsworth; 5th July 2007 at 14:50.
Use signals and slots to connect to some signals where you will check whether the row has been successfully edited and create a new row.
grellsworth (6th July 2007)
Bookmarks