QMenuBar and QMenu doesn't show in Mac OS X - c++

I'm using Qt 4.7.4 on Mac OS X 10.7.4, and I'm trying to add a QMenuBar and a QMenu to my application without success.
When looking for examples, I found the Basic Layouts and the screenshot of the interface on Windows displays the File menu, which is what I'm trying to do:
However, running this example on Mac OS X doesn't show the File menu inside the application window:
and it also doesn't show in the top Mac OS X bar:
It seems that this is either a bug of Qt 4.7.4 on Mac OS X, or we are required to do some tweaks on the source code to make it work on Mac.
How can I fix this problem?
I've found similar posts on Stack Overflow but none helped.

There is no problem in the code, nor in Qt. The example you cite only creates an Exit action in the menu. On OS X, such actions belong in the application menu, not in the File menu. Your application is called qt_menu, and that's how the application menu is called, and that's where you will find the Quit action -- Qt has correctly renamed it to agree with Apple's HIG. On Windows, it'd be customary to call it Exit, on a Mac it's bad style. Qt's behavior is correct, and I can reproduce it.
Add other actions to the file menu, or simply rename the one action from Exit to something else.
Note that Qt doesn't move actions directly based on their name. Qt guesses the action roles based on their name. You should override such guesses and set action roles explicitly using QAction::setMenuRole(). Those roles then get interpreted appropriately on various platforms.

Related

Cross-platform Gtk3 app, menu bar unresponsive at first

I'm writing a cross-platform Gtk3 application in C++. Lately I've been working on the integration with MacOS:
Gtkmm 3.24 obtained via Homebrew;
XCode 12.0;
MacOS Catalina 10.15.
I have derived my application class from Gtk::Application. The application object overrides the 'on_startup()' which calls the base class 'on_startup() and then uses a Gtk builder resource to construct a Gio::Menu object from an XML file, and then 'Gtk::Application::set_app_menu()' to install it:
MyApplication::on_startup()
{
Gtk::Application::on_startup();
// skipping details: ... Gtk builder reads Gio::Menu object from resource file ...
set_app_menu( pMenu );
}
When I first launch my application:
the menu bar is unresponsive. The application menu appears next to the Apple menu in the bar at the top of the screen, but neither responds to mouse clicks;
except from the frozen menu bar, the application is functioning normally and its main window is responsive.
However, then:
click on any other open application's window, that application's menu bar appears;
click on my application's window to switch back to it, its menu bar returns and now works perfectly.
This is 100% reproducible (frozen at first, toggle away to another app and back and now the menu works).
I created another project in XCode and built the Gtkmm example "app_and_win_menus" and the example application behaves the exact same way.
So I think I'm really just looking for a workaround. I've been scouring the net for any information about this problem and saw others complaining generally about frozen menu bars on MacOS but none specific to Gtk (all other applications on this Mac work normally, it's only the apps that I build with Gtk+/Gtkmm 3.24 that exhibit this issue).
I realize this sounds a bit like a bug report and this may not be the place to bring it up, but I'm unsure where to go from here. Any information much appreciated.

How to create an Evernote kind of widget for global menu of a MacOS/X desktop using QT?

How to create an application which stays in top of MacOS, something similar to below image. You can see the Evernote elephant icon.
I don't want to use xcode - because my application already built in QT, it has nice GUI, now I wanted to add extended feature something similar to Evernote. If I click on an elephant it will open a dialog box to write notes. In my case- it's a simple event like on/off buttons.
I have tried and created GUI widget apps but how to make one which resides like Evernote app ?
A custom pop up menu like the one pictured can be done several ways in Qt.
QML is the most modern way of making the menu with the customized styling you are looking for.
Apply the appropriate flags to the window/widget so it appears as a popup.
The same effects can also be done in QWidgets, but takes more code and probably will take longer to make. The flags you are looking for will be found under Qt Window Flags and/or under Qt Widget Attributes.
The stock stylings for Qt for different OS's deal mostly with title bars, status bars, buttons, drop downs, etc.
The base styles for Mac can be found here:
http://doc.qt.io/qt-5/gallery-macintosh.html
Once you go to a customized popup, you have to draw all of it yourself... but the native drawing elements in Qt are friendly enough and get you that look you are trying to do.
There are even some tools for exporting from Photoshop or Gimp directly to QML.
http://doc.qt.io/qtcreator/quick-export-to-qml.html
Hope that helps.
You are looking for a tray icon. Qt implements it in QSystemTrayIcon.
Further information
You may take a look at the System Tray Icon Example.
Many StackOverflow posts exist on this topic.
If you already have a program written for Qt, then you can compile and run it under MacOS/X much the same way you could compile it under (whatever OS you're using now). You'll need to install Xcode because Xcode includes the C++ compiler (clang) you'll need in order to compile your Qt program, but you don't have to use the Xcode IDE if you don't want to. Rather, you can either use the QtCreator IDE under MacOS/X, or you can simply open up a Terminal window and do a "qmake ; make" in the directory where your Qt-based program's .pro file is, and build it from the command line that way.
If, on the other hand, your question is actually about how to add an icon to the global menu of a MacOS/X desktop, then I don't think Qt has an API for that, so you'll need to drop down to using one of MacOS/X's native APIs. That will probably involve learning some Objective-C (or Objective-C++, if you prefer), but integrating a bit of Objective-C/C++ into your Qt app is doable with a bit of work.

Showing the app menu on the top mac window

I have an application that on its main window, has a typical Menu bar, with File, Edit,, View, Tools, Help... with custom submenus. The menu bar is part of the form created using QtCreator, in design view.
I am trying to port this application to Mac OSX - I am a beginner in all things Mac, but I noticed that the typical apps have their menu on the main Mac window. And... it became a requirement, if I can, to move the app menu bar to the higher level menu...
I don't eve know how to begin, searching typical keywords did not yield anything useful.
I imagine that there is some type of object I can access and set, in case my os is MACX ?
Are there any examples, or documentation, on setting the top menu in Mac ?
using Qt 4.8... c++... the Mac I have to build on has 10.6.8 on it
According to this page, Qt should translate your menu bar into a native OS X menu bar automatically, or with little work (though that doc is for 5.3). Have you tried doing this stuff already? If so, what problems are you running into specifically?

Qt: QTabWidget not responding to clicks

I am creating a Qt GUI with C++.
My intention is to prompt the user when the tab bar is double clicked or single clicked. This works when I create the GUI using Qt Creator; however, when I qmake and run with XCode, the GUI does not respond to either single or double clicks.
I am using the signals tabBarDoubleClicked(int) and tabBarClicked(int) from QTabWidget.
Why do I experience different behavior when building with Qt Creator as opposed to XCode?
How can I make XCode recognize single and double clicks to the tabBar?
Edit: Also, I cannot find documentation for these functions. I find that strange due to Qt Creator listing this as applicable signals. Why?
One possible option is - as you write in the comment -, that you are using different Qt versions.
Another option in general is that people invoke qmake slightly different, e.g. from a different folder than QtCreator, etc.

Is it possible to add an item to the right-click context menu of a Mac OS programmatically?

I have a program that works with a variety of files on both the Windows and Mac OS.
I would like to give the user the option of adding a new option to their right click/control click context menu to the effect of "Compress with [Name of App]".
I know this is quite possible in Windows with modifications to the registry, but is there a way to achieve this for the Mac? Perhaps using C++ or objective C?
Yes, you can. You need to make a contextual menu plugin. Apple has contextual menu plugin sample code on its developer site.
Here's a guide: Writing Contextual Menu Plugins for OS X, part 1