2

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.

5
  • 2
    No, Qt doesn't, because it is a platform-specific feature. You need to use WinAPI. Btw, for some stuff there are special classes: doc.qt.io/qt-5/qtwinextras-module.html Jun 14, 2016 at 7:46
  • 1
    Try this: stackoverflow.com/questions/13680415/… Jun 14, 2016 at 7:49
  • Minion, can you clarify exactly what you mean? Your question sounds like it needs a file-select dialog box but others have questioned that.
    – paxdiablo
    Jun 14, 2016 at 7:55
  • I'm talking about common function in Windows, such as 'locate the file', 'explore here'. I have clarified this in my question.
    – minion
    Jun 14, 2016 at 8:13
  • There is no such feature in iOS or Linux? Do any body know?
    – minion
    Jun 14, 2016 at 8:28

2 Answers 2

3

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.

0

Yes, there is. QFileDialog is the class you are looking for.

In python it could look like this:

QFileDialog.getSaveFileName(self, "Choose a path and filename", os.getcwd().replace("\\", "/") +
                                  "/data/highlighted_file.txt", filter="Text Files (*.txt)")

The os.getcwd().replace("\\", "/") part merely selects your current folder and replaces the backslashes with forward slashes.

Edit: It seems like I misinterpreted your initial question. The other answer by @Jon Harper is probably what you are looking for.

2
  • 4
    QDir::toNativeSeparators / QDir::fromNativeSeparators Jun 14, 2016 at 7:44
  • Qfilsytemmodel with qtreeview
    – Mike
    Aug 28, 2018 at 20:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.