7

I am porting my Qt app to Mac OS X. On Windows/Linux I've used a QLineEdit to provide a search feature in the Help menu.

In Mac OS X, I saw something like this is built-in: enter image description here

How can I access this search bar with Qt (i.e., add my own elements to it)? I looked at QMenuBar in the docs but couldn't find anything relevant. If it's not possible, can I at least use some native API from my C++ Qt app?

Thanks a lot.

houbysoft
  • 32,532
  • 24
  • 103
  • 156

4 Answers4

4

This is the Spotlight For Help search field, which is entirely controlled by the system. It automatically provides results from your application's Help Book and menu items. AFAIK you can't populate it "manually". It works automatically when you create a Help Book for your application.

See Apple Help Concepts: The Help Menu.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Gave you a +1, looks like this is my only option. I'm going to wait for maybe a day to see if there isn't a way to do it directly from the program, otherwise I'll accept this. – houbysoft Jul 13 '11 at 14:40
  • 1
    just discovered that in the Terminal app, the help menu also shows man pages. Try typing `man` in the spotlight search field in Terminal. Then if you click on it it opens a new terminal window showing the man page. Therefore, it seems that maybe it could be populated manually? The man pages are not in the Help Book nor the menu items. – houbysoft Jul 13 '11 at 16:09
  • Hmm, very intriguing! Sorry, I don't know if that's a public API. – deceze Jul 13 '11 at 22:19
3

It seems you can't do this directly through Qt, however, you can implement this one feature in Objective-C++/Cocoa.

It is possible through the - registerUserInterfaceItemSearchHandler method of NSApplication to register a custom function for querying and returning search items.

QtHelp seems to have support for automatic indexing, which means you can delegate search to that.

Symaxion
  • 785
  • 7
  • 21
3

If you add a Help menu to your application, Qt will automatically add the search box. See http://doc.qt.io/qt-4.8/mac-differences.html#menu-bar

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
koan
  • 3,596
  • 2
  • 25
  • 35
  • Yes, it is added automatically, but what I need is to add my own items to it -- looks like I have to create a Help Book as per deceze's answer below. Right now it only searches in menu items. – houbysoft Jul 13 '11 at 13:23
0

You can get rid of the Search menu Mac OSX adds to Help menus simply by calling the menu something else. Just adding a space:

QMenu *helpMenu = menuBar()->addMenu(" Help"));

will work.

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62