i have checked here, and tried the code independently and it worked...but inserting the code in my QTreeView app...it opens up the explorer user libraries with 'My Documents' in focus
i use subprocess.Popen(r'explorer /select,"file_path"')
here is my code
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)