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.

Community
  • 1
  • 1
minion
  • 561
  • 4
  • 17
  • 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: http://doc.qt.io/qt-5/qtwinextras-module.html – Dmitry Sazonov Jun 14 '16 at 07:46
  • 1
    Try this: http://stackoverflow.com/questions/13680415/how-to-open-explorer-with-a-specific-file-selected – Dmitry Sazonov Jun 14 '16 at 07: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 '16 at 07: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 '16 at 08:13
  • There is no such feature in iOS or Linux? Do any body know? – minion Jun 14 '16 at 08:28

2 Answers2

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.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42
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.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Ian
  • 1,688
  • 18
  • 35