[Qt-interest] [OS X] Auto-hide toolbar when going "native fullscreen" on "Lion"?
Till Oliver Knoll
till.oliver.knoll at gmail.com
Wed Aug 3 10:26:24 CEST 2011
Hi,
how do I auto-hide the (native) toolbar when going fullscreen with the
new "Lion fullscreen API" (Cocoa Qt)?
I managed without big effort to make use of the new "fullscreen API"
of "Lion" (Mac OS X 10.7), see below. But I also want the toolbar
(which I have set to "native" with
http://doc.qt.nokia.com/latest/qmainwindow.html#unifiedTitleAndToolBarOnMac-prop)
to disappear. According to the Apple docs:
"A window delegate may also specify that the window toolbar be removed
from the window in full-screen mode and be shown automatically with
the menu bar by including NSApplicationPresentationAutoHideToolbar in
the presentation options returned from the
window:willUseFullScreenPresentationOptions: method of
NSWindowDelegate."
Apparently the way to go is to use the NSApplicationDelegate, which is
"auto-wired" at application startup, as defined in some NIB file (to
my understanding so far).
I noticed that there is already a "Qt NSApplicationDelegate":
http://svn.netlabs.org/repos/qt4/trunk/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h
Off course there is no public API to access this, but currently I am
not looking for a "clean" solution, just for a "proof of concept"
solution. So can I somehow - without hacking the Qt sources for now -
access this delegate instance and "injecting" the method
window:willUseFullScreenPresentationOptions which would return the
desired flag? To my understanding in Objective-C one can "override" or
even add new methods to existing objects without subclassing, using
the Objectvive-C feature "Categories".
I tried to set the flag NSApplicationPresentationAutoHideToolbar on
the global NSApp (NSApplication) instance directly by calling
setPresentationOptions, before or after calling 'toggleFullScreen',
but to no avail, the flags did not change (according to debug output)
and the toolbar remained visible.
I just noticed that there is a toggleToolbarShown method in NSWindow,
maybe I could just call this explicitly when toggling fullscreen as
well. Will try this evening.
Any other ideas or thoughts welcome :)
Off course it would be great if Qt would provide this "native
fullscreen mode" itself, maybe controllable via a flag (not every
application would want to use the "native fullscreen mode" on Lion and
would prefer the existing functionality, even though I could not think
of any good reason right now...). Any chance for Qt 4.8? :) (By the
way, I am using an outdated Qt 4.7.1 Cocoa - goes without saying on OS
X 10.7 ;)
This is what I have achieved so far, maybe someone else finds this helpful:
- adding an *.mm source file to my project in which
- I set the flag NSWindowCollectionBehaviorFullScreenPrimary (value 1 << 7) (*)
by sending the message setCollectionBehavior to the NSWindow instance which
- I got via http://doc.qt.nokia.com/latest/qwidget.html#winId (NSView
-> NSWindow) and
- I send the message toggleFullScreen to the NSWindow whenever
- I activate the corresponding QAction in my "View" menu
(*) This adds the "fullscreen" icon into the title bar
Also refer to
http://developer.apple.com/library/mac/#documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html
By the way, for Objective-C noobs such as myself who don't even know
how to "call a method in Objective-C", here's a fantastic primer:
http://cocoadevcentral.com/d/learn_objectivec/
Short and to the point. And no, you don't "call" a method; you send
"messages"... ;)
Cheers,
Oliver
More information about the Qt-interest-old
mailing list