Search code examples
qtpyqtqt4pyqt4pyqt5

Does Qt support 'Open a folder and highlight a particular file'?


Does Qt provides a means of 'Open a folder and highlight a particular file'? I found a solution Open a folder and highlight a particular file with WPF, but it's only for Windows. Does Qt provide a universal solution?

After doing a file search, I would like to show the file location hyperlinks in QTextBrowser. Let users click on the links to locate the file in a file manager (not open them). I'm not so sure if this feature is aslo available for iOS or Linux.


Solution

  • No. What you are trying to do is platform-specific (i.e. instruct the native file browser to open and perform some specific action) and therefore not supported.

    Qt does have platform-specific features, but they largely are focused on enabling platform-specific interaction (like getting a native OS X menu handle) rather than integrating platform-specific behavior. Yes, pretty much all platforms have some form of file browser, but they also have lots of APIs, quirks, and features not available elsewhere. Qt does its best to balance being feature-rich without binding too tightly to the platform.

    The closest you can come is with QDesktopServices::openUrl, but that just opens the directory. Check out QProcess::execute to call the native file browser along with command-line arguments.