在qtreeview中通过:
indexItem = self.model.index(index.row(), 0, index.parent())
filePath = self.model.filePath(indexItem)
可以获得文件路径,然后通过
if(os.path.isfile(u''+str(unicode(filePath)).decode('utf-8'))):
import subprocess
subprocess.call(['notepad.exe', filepath])
即可打开文件,但是这只限于英文的路径和英文的文件
对于中文的解决办法其实很简单
只需要在头部添加
# -*- coding:utf-8 -*-
然后打开文件
subprocess.call(['notepad.exe', (u''+str(unicode(filePath))).encode('gbk')])
即可打开通过windows下的notepad打开文件