Question

I have a basic QTableView displaying data from an SQLite table with QSqlTableModel.

Data entry is done by the parent dialog having a number of widgets representing the field data and an "Add" button. Data removal is done via a "Remove selected rows" button.

Everything is very functional but I find it incredibly clunky and want to try a Better Way.

Ideally, I would like an empty row in the view into which the user can simply begin typing their data. At the end of each row a button to delete that specific row (kind of like the vertical headers but with a push button instead of row numbers).

I think this may be achievable with sub-classing QTableView, but the idea of having to repaint everything is a little daunting...

Does anyone have advice on how I could go about this, maybe using Delegates (admittedly something I have not used before) or another simpler method that I have overlooked??

Was it helpful?

Solution

From what you describe you shouldn't have to worry about repainting anything. Simply you can add a QButton in the last cell of row. There are several answers/articles on adding a button to a QTableView:

  1. http://qtadventures.wordpress.com/2012/02/04/adding-button-to-qviewtable/
  2. Adding button to QTableview

Secondly, with allowing a user to add a row directly read this article sections on making the model editable and inserting/remove rows.

  1. http://doc.qt.io/archives/qt-4.7/model-view-programming.html#making-the-model-editable
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top