我有一个QTreeView和QFileSystemModel作为模型.
QTreeView将SelectionBehavior设置为SelectRows.
在我的代码中,我读了一个数据集来选择,然后通过以下方式选择它们:
idx = treeview->model()->index(search);
selection->select(idx, QItemSelectionModel::Select);
Run Code Online (Sandbox Code Playgroud)
这将选择一个单元格,而不是行..
添加了一个愚蠢的解决方法,但宁愿以正确的方式解决这个问题.
for (int col=0; col< treeview->model()->columnCount(); col++)
{
idx = treeview->model()->index(search, col);
selection->select(idx, QItemSelectionModel::Select);
}
Run Code Online (Sandbox Code Playgroud)
或者是^^唯一的方法吗?