Hi carvi,
I thought about emitting signal "activated" from QTableView object
Read the documentation of QAbstractItemView::activated(const QModelIndex& index) if you want to know when it emitted. But if you want a simple solution, try this:
- Connect your button to a slot
- Then in the body of the slot, use selection model form your view to find selected items, so you can delete these items
The code would be something like this:
// connect to a slot
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeItems()));
.....
// slot definitions
void MyWidget::removeItems()
{
// ex: delete first row in selection
QModelIndex index
= selectionModel
->selectedRows
().
first();
tableModel->removeRow(index.row());
tableModel->submit();
}
// connect to a slot
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeItems()));
.....
// slot definitions
void MyWidget::removeItems()
{
QItemSelectionModel *selectionModel = view->selectionModel();
// ex: delete first row in selection
QModelIndex index = selectionModel->selectedRows().first();
tableModel->removeRow(index.row());
tableModel->submit();
}
To copy to clipboard, switch view to plain text mode
Next thing: How to set "read only" or frozen for column in table that is displays in QTableView?
I usually create a model that inherited from QSqlQueryModel, QSqlTableModel or QSqlRelationalTableModel, then reimplement data(), setData() and flags() method.
Qt Query Model Example is a good place to start creating your own custom SQL model.
Bookmarks