gpt4 book ai didi

c++ - 以编程方式在 QTreeView 中选择一行

转载 作者:IT老高 更新时间:2023-10-28 22:17:30 27 4
gpt4 key购买 nike

我有一个以 QFileSystemModel 作为模型的 QTreeView。

QTreeView 将 SelectionBehavior 设置为 SelectRows。

在我的代码中,我读取了一个要选择的数据集,然后通过以下方式选择它们:

idx = treeview->model()->index(search); 
selection->select(idx, QItemSelectionModel::Select);

这会选择一个单元格,而不是行。 .

添加了一个愚蠢的解决方法,但宁愿以正确的方式解决这个问题。

for (int col=0; col< treeview->model()->columnCount(); col++) 
{
idx = treeview->model()->index(search, col);
selection->select(idx, QItemSelectionModel::Select);
}

或者这是 ^^ 唯一的方法吗?

最佳答案

如果要选择整行,应使用以下内容:

selection->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);

请注意,您有时可能首先要清除选择:

selection->select(idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);

关于c++ - 以编程方式在 QTreeView 中选择一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4967660/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com