Qt QTreeView - 不满足条件时恢复到先前的选择
在 QTreeView 选择更改时,如果某个特定情况我想恢复到之前的选择 不满足条件。
例如:
void Editor::treeFolderSelected(QModelIndex const& index)
{
if(widget) {
if(!widget->trySaveChanges()) {
//revert to previous, validation failed
return;
}
}
//do normal behaviour
}
目前,我没有看到直接的方法来执行此操作,因为 QModelIndex
不提供有关之前选择的内容的任何信息。
有人对实现这一点的最佳方法有什么建议吗?
On QTreeView selection change, I would like to revert to the previous selection if a certain
condition is not met.
For example:
void Editor::treeFolderSelected(QModelIndex const& index)
{
if(widget) {
if(!widget->trySaveChanges()) {
//revert to previous, validation failed
return;
}
}
//do normal behaviour
}
Currently I am not seeing a straight forward way to do this, as the QModelIndex
does not provide any information regarding what was selected previously.
Does anyone have any suggestions on the best way to implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
视图选择有自己的模型,
QItemSelectionModel
,带有信号为您提供新的和以前的选择。The view selection has its own model,
QItemSelectionModel
, with signals that give you the new and previous selection.