Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在QTreeView或QListView中设置ItemFlag?_Python_Pyqt5_Pyside2 - Fatal编程技术网

Python 如何在QTreeView或QListView中设置ItemFlag?

Python 如何在QTreeView或QListView中设置ItemFlag?,python,pyqt5,pyside2,Python,Pyqt5,Pyside2,更新1: 基于QFileSystemModel()的QTreeView 如何在指定的树项目上“设置标志” 在子类QFileSystemModel()中 类MyTreeModel(QFileSystemModel): def uuu init uuu(self,parent=None): super(MyTreeModel,self)。\uuuu init\uuuuu(父级) #假代码: 如果当前_index.parent()==treeView.rootIndex(): #它是第二级文件夹。 #

更新1: 基于QFileSystemModel()的QTreeView

如何在指定的树项目上“设置标志”

在子类QFileSystemModel()中

类MyTreeModel(QFileSystemModel):
def uuu init uuu(self,parent=None):
super(MyTreeModel,self)。\uuuu init\uuuuu(父级)
#假代码:
如果当前_index.parent()==treeView.rootIndex():
#它是第二级文件夹。
#将此树项目设置为不可选择。
当前_index.setFlags(^Qt.itemisselect)

我从这里得到灵感:

与setData()类似,您不能将setData()设置为QFileSystemModel,但可以修改data()以在从模型读取数据时添加代码

不能直接将flags()设置为QFileSystemModel,但可以修改flags()以更改返回的数据

类MyTreeModel(qtwidts.QFileSystemModel):
#...
def标志(自、索引):
flags=super(MyTreeModel,self).flags(index)
#确定目录级别。
如果自索引_级别(索引)==2:
flags=标志^QtCore.Qt.ItemIsSelectable
返回标志

哪些项目和依据是什么?在运行期间,该标志是否会因任何原因而更改?模型是静态的还是布局发生了变化?标志始终由模型提供(意味着必须重新实现);如果希望能够以编程方式为特定索引设置标志,则应该为每个索引及其自定义标志(如果有)保留内部引用。也就是说,请首先提供一个答案,这个问题太广泛了。