如何在QTreeView中获取选择更改通知
How to get selection changed notification in QTreeView
我正在努力解决这个问题,似乎我必须使用QItemSelectionModel,但我找不到如何连接的示例。
我已经在.h文件中定义了。
QItemSelectionModel* selectionModel;
现在在视图的构造函数中,我设置:
selectionModel = ui->treeView->selectionModel();
// the following line is not compiling!
connect(ui->treeView->selectionModel(), SIGNAL( ui->treeView->selectionModel(const QModelIndex&, const QModelIndex &) ),
this, this->selectionChanged ( QItemSelection & sel, QItemSelection & desel) );
我以为会有预定义的插槽,但我找不到,所以我添加了这个(我在这里找到的语法)
void MyDialog::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
qDebug() << "Item selection changed";
}
我还尝试用QModelIndex替换QItemSelection,但仍然不起作用。
当选择发生变化时,我需要做什么才能得到通知,而不是明显地抓住新选择的项目?
QObject::connect方法应按如下方式使用:
QObject::connect(sender, SIGNAL(signal_method), receiver, SLOT(slot_method));
所以在你的情况下,它应该是类似的东西
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(mySelectionChanged(const QItemSelection&,const QItemSelection&)));
相关文章:
- 如何使用默认参数等选择模板专业化
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 选择要调用的构造函数
- C++选择排序算法中的逻辑错误
- QTreeView幻灯片多选后无法使用单击选择
- 无法获取菜单选择以运行函数.C++
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 在C++中,如何通过几种类型从元组中选择多个元素
- 讨论 - 创建矩阵时的数组与向量的向量 - 什么是最实用的选择
- 对可变参数使用声明.如何选择正确的功能
- 选择选举获胜者的程序
- 如何选择在 csv 文件中输出的位置
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 函数如何通知用户它基于函数原型抛出异常?
- 程序在尝试猜测它选择的随机数时进入无限循环?
- 如何在ECS框架中更新组件数据和通知系统
- 为什么日食总是发生错误"An internal error occurred during: "通知选择侦听器". java.lang.StackOverflowError"
- 如何在QTreeView中获取选择更改通知
- 是否可以编写一个windows应用程序,当在另一个窗口应用程序中选择文本时,该应用程序会收到通知
- 非阻塞选择通知