我已经检查了here,并且独立尝试了代码并且它有效...但是在我的QTreeView应用程序中插入代码...它打开了带有“我的文档”的浏览器用户库&#39 ;焦点
我使用subprocess.Popen(r'explorer /select,"file_path"')
这是我的代码
def on_clicked(self, index):
# self.path = self.fileSystemModel.fileInfo(index).absoluteFilePath()
self.path = self.fileSystemModel.filePath(index)
print(self.path
def tabMenu(self, positon):
self.tmenu = QMenu()
self.open = self.tmenu.addAction('Open')
self.open_file_location = self.tmenu.addAction('Open File Location')
self.tmenu.addActions([self.open, self.open_file_location])
action = self.tmenu.exec_(self.temp_treeView.viewport().mapToGlobal(position))
if action == self.open:
os.startfile(self.path, 'open')
elif action == self.open_file_location:
print(self.path)
subprocess.Popen(r'explorer /select,' + self.path)
答案 0 :(得分:0)
self.path = self.fileSystemModel.filePath(index)
返回/
无法访问的subprocess.Popopen(r'explorer /select,"path")
文件路径..您需要将/
转换为\
才能使其正常工作...按subprocess.Popen(r'explorer /select,'+"{}".format(path).replace('/', '\\'))