- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我使用QTreeView
和QFileSystemModel
制作了一个非常简单的文件浏览器。现在 QTreeView
可能会混淆它的级联结构:
添加了一个选项,用于将所选目录设置为临时根位置:
在代码中,这是通过给定路径将根节点设置为QTreeView
的方法。目前我不知道如何检查无效路径:
void FileView::setRootPath( const QString&str )
{
// This didn't work
//model->setRootPath(str);
//This works
ui.treeView->setRootIndex(model->index(str));
}
但我也希望能够恢复此操作并返回目录树。我认为我需要的是在以下注释行下获取一些代码:
void FileView::rootUpOneLevel() {
QString rootPath;
// Get the current root index path into the QString
...
// Set the path as new root index, provided it's not out of the original root
setRootPath(rootPath);
}
最佳答案
我想,如果你想重置 View 并显示整个目录树,你只需要做:
ui.treeView->setRootIndex(QModelIndex());
即通过提供无效的模型索引,即根模型索引。
更新
为了更上一层楼,您需要调用相同的 setRootIndex()
函数,但将父模型索引作为参数:
void FileView::up(const QString &str)
{
QModelIndex idx = model->index(str);
ui.treeView->setRootIndex(idx.parent());
}
或
// Goes one level up from the current
void FileView::up()
{
QModelIndex currentRoot = ui.treeView->rootIndex();
ui.treeView->setRootIndex(currentRoot.parent());
}
关于c++ - 获取 QTreeView 的根索引并返回上一级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32578884/
有人知道如何为 QTreeView 项目的子组实现/实现具有不同颜色的 QTreeView 吗? 像这样的东西: 有没有人做过类似的事情,可以给我一个教程或操作方法的链接,或者示例代码也不错。目前我完
在 Qt 文档中 http://doc.qt.io/qt-5/model-view-programming.html#model-subclassing-reference ,据说,如果你的模型是可排
我正在使用 Qt 4.7.0,一个多列的 Qtreeview。 我想要做的是“简单”:我想要一条线增加它的高度 , 当它被选中时。 代表是否足以做到这一点? 我已经通过 QTableView 经历了一
我需要在 QTreeView 中通过拖放来实现行移动,并在行之间显示放置指示器。我想知道是否有一种方法可以覆盖指标绘图,因此它仅针对行之间的所有层次结构显示(不是项目周围的矩形),该行必须与整行一样宽
我现在正在测试 QTreeView 功能,我对一件事感到惊讶。似乎 QTreeView 内存消耗取决于项目数 O_O。这是非常不寻常的,因为这种类型的模型 View 容器只跟踪显示的项目,其余项目都在
我正在尝试让 QTreeView(使用底层 QFileSystemModel)显示目录树。如果我将 RootPath 设置为父目录,那么我会看到所有子目录,但看不到父目录。如果我将 RootPath
我尝试编写一个基于 QTreeView 的可编辑表格,在单元格中包含自动换行的内容,而这些单元格又应该像 MSWord 中表格中的普通单元格一样扩展高度(整个文本可见),但遇到了无法克服的障碍: 首先
我想要一个 TreeView ,它在各个列中显示项目名称、项目描述和两个相关的 bool 值。我首先修改 Editable Tree Mode example ,所以有一个 TreeModel 跟踪一
我想在我的程序中实现一个带有嵌套子级别的树,我正在寻找这两种( View /小部件)中的哪一种最适合我的目标。 我有一个任务完成/错过/失败的天数列表,每个任务都有完成/错过/失败的次数,最后是当天的
我想要我的 QTreeView总是展开所有的项目。在这种情况下,所有展开按钮/装饰都是不必要的,我想摆脱它们。我怎样才能删除所有这些? setRootIsDecorated只会删除第一级的按钮....
我有一个 QTreeView 子类(和 QAbstractItemModel 子类),它有一个漂亮的水平标题。我想添加垂直标题(从左侧向下)以匹配。但与具有单独的垂直 ( setVerticalHea
我想在 Qt 中实现对 QTreeView 对象的手动控制。 (这意味着将对一切进行编程控制,包括导航)到目前为止,我已经在 sibling 中实现了导航/选择。但是,我想建立一个更容易控制的状态,无
我想在 Qt 中实现对 QTreeView 对象的手动控制。 (这意味着将对一切进行编程控制,包括导航)到目前为止,我已经在 sibling 中实现了导航/选择。但是,我想建立一个更容易控制的状态,无
我有需要在 QTreeView 中显示的自定义数据。我从 QAbstractTableModel 派生了我的模型,并制作了自己的 rowCount()、columnCount()、data() 和 h
我的小部件中有一个QTreeView。当在 View 中选择一个项目时,我有 在详细信息窗口中更新一系列信息小部件的信号处理程序 关于所选项目。然后,用户可以编辑项目详细信息并提交 更改回模型。 更改
在下面的代码中,QTreeView 小部件始终占用最大空间,并为 QPushButton 小部件留下最小空间(代码后的图像)。如果 QTreeView 小部件被另一个 QPushButton 替换(当
我正在使用 Qt4,我正在尝试显示带有 QTreeView 的模型。我拥有的模型由多个批处理过程组成,每个批处理都有一些元素,每个元素都有一些子元素(同一批元素具有相同数量的子元素,但我认为这与问题无
我有一个 qt 对象 QTreeView我想切换标签位置。基本上我有一个填充的 TreeView。和功能 columnViewportPosition ( int column ) 第一列返回 0,第
我目前正在尝试制作一个 QTreeView 来显示计算机上文件夹的内容。但是,我遇到了一些奇怪的问题,其中 .和 .. 显示在 TreeView 中,我不希望这种情况发生。我该如何禁用显示 .以及 .
我在从 QTreeWidget 迁移到 QtreeView 时遇到问题。对于 QTreeWidget 来说显而易见且微不足道的事情在 View 中似乎是不可能的。具体来说:我有一个带有 TreeVie
我是一名优秀的程序员,十分优秀!