简体   繁体   中英

PyQt5 | How to open a folder with a file preselected?

Currently I can open a folder by using

dirPath = os.path.dirname(os.path.abspath(self.oVidPath))
QDesktopServices.openUrl(QUrl.fromLocalFile(dirPath))

I want to know if there is anyway I can open folder with a file preselected?

I am okay if it only works on linux systems (nautilus is preferred)

edit : This application is only going be for linux systems

For windows

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.Qt import QProcess

if __name__ == '__main__':
    app = QApplication(sys.argv)
    command = "explorer /e, /select, c:\\windows\\regedit.exe"
    process = QProcess()
    process.start(command)
    sys.exit(app.exec_())

For Linux

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.Qt import QProcess

if __name__ == '__main__':
    app = QApplication(sys.argv)
    command = "nautilus /var/log/dpkg.log"
    process = QProcess()
    process.start(command)
    sys.exit(app.exec_())

FYI https://askubuntu.com/a/82717/249546

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM