Qt on Mac — how to access “search” in help menu

一世执手 提交于 2021-02-08 13:43:43

问题


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.


回答1:


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.




回答2:


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.




回答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




回答4:


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.



来源:https://stackoverflow.com/questions/6673612/qt-on-mac-how-to-access-search-in-help-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!