PDA

View Full Version : Double menu items on os x el capitan



rwhartzell
4th March 2016, 00:21
I'm having a problem with certain menu items displaying twice on OS X El Capitan.
The menu items are created in designer so just generated code. If I remove my menu item
with:

ui->menu_View->removeAction(ui->action_exit_full_screen);
then no item shows at all. Any idea why?

11764
11765

rwhartzell
11th March 2016, 20:16
This is about all I could find related to this. From the OS X Developer Release Notes.
https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/#10_11FullScreen

AppKit automatically creates an "Enter Full Screen" menu item after the application finishes launching if an equivalent menu item isn't found.
If this menu item should not be created for your app, before NSApplicationDidFinishLaunchingNotification is sent you may set the
NSFullScreenMenuItemEverywhere default to NO.


(void)applicationWillFinishLaunching:(nonnull NSNotification *)notification {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"];
}


Is there a way I can leverage this in Qt?

ChrisW67
11th March 2016, 21:34
In your first post is the menu item without the shortcut yours? If so, perhaps creating yours with the shortcut will convince OS X it already has an " equivalent item."

rwhartzell
11th March 2016, 22:36
The shortcuts are mine... Tried a few different things including removing the menu item but haven't found anything that works.

ChrisW67
12th March 2016, 05:21
You could try creating your menu entry, waiting until the UI is shown (use a zero timer and a simple slot), and then removing/hiding your menu item leaving the OS X Auto-magic one. Yes, it would be an ugly hack.

You can call Objective C functions from C++ if you jump through hoops
http://stackoverflow.com/questions/1061005/calling-objective-c-method-from-c-method

I am not a Mac owner so I cannot be more specific.

rwhartzell
12th March 2016, 07:57
You're timer idea was simple enough and works fine except theres no short cuts. I guess that will work until Qt catches up with El Capitan. Thanks for the pointer.

For anyone interested this is what i did because i still build and run on Yosemite.

In the constructor...

#if defined Q_OS_MAC
if (QSysInfo::productVersion() == "10.11") {
QTimer *timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(elCapitanMenuHack()));
timer->start(0);
}
#endif

And then a private slot...

void MainWindow::elCapitanMenuHack() {
ui->menu_View->removeAction(ui->action_enter_full_screen);
ui->menu_View->removeAction(ui->action_exit_full_screen);
}

ChrisW67
12th March 2016, 09:23
You might like the QTimer::singleShot() static function.

rwhartzell
12th March 2016, 16:15
Even better just needs to be set to a non zero value.


#if defined Q_OS_MAC
if (QSysInfo::productVersion() == "10.11") {
QTimer::singleShot(1, this, SLOT(elCapitanMenuHack()));
}
#endif

Thanks again.