Reputation: 332
I am trying to create a function that opens the file location from its shortcut into my own file explorer and highlight the file from the file explorer.
def openFileLocation():
self.Directory = os.path.dirname(self.favoritesListWidget.currentItem().data(QtCore.Qt.UserRole)[2])
ProjectOSP.setCurrentIndex(1)
self.fileExplorerListWidget.setCurrentItem(self.favoritesListWidget.currentItem().text())
reloadListWidget()
Upvotes: 0
Views: 1257
Reputation: 332
I have solved it by using QtWidgets.QListWidget.findItems() method by using the MatchExactly flag and the string from my shortcut's name extracted from the path of that shortcut then reloading the fileExplorer then iterating through the results which should be one, and setting the current item to that exact item.
def openFileLocation():
data = self.favoritesListWidget.currentItem().data(QtCore.Qt.UserRole)
self.Directory = os.path.dirname(data[2])
ProjectOSP.setCurrentIndex(1)
reloadListWidget()
[self.fileExplorerListWidget.setCurrentItem(x) for x in self.fileExplorerListWidget.findItems(data[0]+'.'+data[1], QtCore.Qt.MatchExactly)]
You can find more about findItems here
Upvotes: 2