First you have alter the model: e.g. QAbstractItemModel::removeRow(). To get the current selected item: QAbstractItemView::selectionModel() and then QItemSelectionModel::currentIndex().
First you have alter the model: e.g. QAbstractItemModel::removeRow(). To get the current selected item: QAbstractItemView::selectionModel() and then QItemSelectionModel::currentIndex().
Thanks for answer. I'll try to change my code but now I'm not sure I chose the corret class. I'm using QListView to display data from SQL table. I'm reading records and putting them in QStringList. Next I'm creating my model. User can add/delete new record to QListView/database. So in that case, should I use QListWidget or QListView? What do you think would be better for me to use for this?
Ehm, QTreeView with a QSqlTableModel or QSqlQueryModel. That's the standard case for them. Seriously, spend some time to read the parts about model and views at the docs. It might be difficult in the first place BUT it will save you a lot of pain in the a***!
Use QTreeView!
damon_1990 (4th October 2011)
Ok thanks for helpI chose QListView because I want to display only one column from table, but maybe it was more easy to use QSqlTableModel and hide columns.
Bookmarks