Interactive QSqlTableModel
Please could you give me an advice. I am using QSqlTableModel class to access the database table and QTableView to view it. What signal of what instance should I handle to know about user move the cursor in QTableView?
I want to update the content of TableView B after the cursor moved in QTableView A (Table B have foreign keys to table A in database)
May be somewhat from this h开发者_运维问答ttp://doc.trolltech.com/latest/qabstractitemmodel.html?
Thanks.
Ivan, if you are talking about table cursor, you can reimplement QAbstractItemView::moveCursor method which is virtual.
If you're talking about mouse cursor, you can use QAbstractItemView::viewportEvent method to detect mouse move event. You need to set QWidget::setMouseTracking(true) to the viewport of your QTableView.
Hope that helps
Another way is using the selection model
Using a selection model
The standard view classes provide default selection models that can be used in most applications. A selection model belonging to one view can be obtained using the view's
selectionModel()
function, and shared between many views withsetSelectionModel()
, so the construction of new selection models is generally not required.
If you have an shared selection model the views will be updated not matter which one changes. You can then react to it. The selection flags control if you want a cell, row or multiple selections.
See also working with selections :
//selection changes shall trigger a slot
QItemSelectionModel *selectionModel= treeView->selectionModel();
connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));
}
精彩评论