您的模型可以實現每次要更改選擇時發出的信號。就像這樣:
void CMyModel::sigUpdateSelection(const QItemSelection & selection, QItemSelectionModel::SelectionFlags flags);
而且你可以把這個信號連接到你的表視圖的QItemSelectionModel。這是你如何讓選擇模型:
QTableView* view = new QTableView(parent);
QItemSelectionModel* selectionModel = view->selectionModel();
QItemSelectionModel
有一個插槽select()
。這是您連接信號的地方。
這是你將如何發出:
// Add to current selection
emit sigUpdateSelection(QItemSelection(indexLeft, indexRight), QItemSelectionModel::Select);
// Clear current selection and select new one
emit sigUpdateSelection(QItemSelection(indexLeft, indexRight), QItemSelectionModel::ClearAndSelect);
你可以點擊專注於通過在線模擬或雙擊它。也許它可以工作? – Boiethios
但是如何?我只有指向表項(包含在模型中的單個項目,視圖使用mdoel作爲源) - 我如何從這裏到達那裏? – Arker
哦,是的,我讀QTableWidget而不是QTableView。我從來沒有使用過QTableView。 – Boiethios