[Qt-interest] [OS X] Auto-hide toolbar when going "native fullscreen" on "Lion"?

Till Oliver Knoll till.oliver.knoll at gmail.com
Thu Aug 4 10:51:56 CEST 2011


2011/8/3 Till Oliver Knoll <till.oliver.knoll at gmail.com>:
> Hi,
>
> how do I auto-hide the (native) toolbar when going fullscreen with the
> new "Lion fullscreen API" (Cocoa Qt)?
> ...
> "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).

Well, off course I confused the NSApplicationDelegate with the NSWindowDelegate!

So I quickly implemented my own NSWindowDelegate instance which would
provide the proper presentation hints and upon application start I set
this delegate on the NSWindow which is associated with my QMainWindow.

No good!

This off course replaces the existing window delegate - the one
provided by Qt internally - and messes up the whole window layout,
resizing the window has no effect on the content etc.


So what about modifying the existing delegate?

As a matter of fact there exists also a QCocoaWindowDelegate:

  http://qt.gitorious.org/qt/qt/blobs/master/src/gui/kernel/qcocoawindowdelegate_mac_p.h

Off course it is also very private, but Objective-C provides a very
clever way to extend functionality without subclassing: Categories
(still a very hackish way, mind you, since we try to extend a very
private class of Qt)!

So I quickly added a category (fullscreen) with the desired method
-window:willUseFullScreenPresentationOptions: (my binary Cocoa Qt
package did not provide the necessary private
qcocoawindowdelegate_mac_p.h header, so I quickly created a new such
file with the content given from above GIT source).

This compiled fine, but I got a linker error saying that the
"_obj_c_qcocoawindowdelegate" (or similar, can't remember the exact
symbol name) could not be found! Apparently this is not exported from
QtGui library. Note that in my own Category I also used this
QT_MANGLE_NAMESPACE for the class name (also tried without, same
linker error)...

Maybe I did something wrong, I just tried quickly...

> 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.

Well, this method only has an effect on the Window in it's normal
state, so what happens when calling this method before going
fullscreen is that in the original window the toolbar disappears, but
not in the one which is now fullscreen!


I did not mention that I also tried the obvious methods such as
QToolBar::setVisible() in combination with setting the toolbar to
"non-native" just before going fullscreen etc., but results where
always mixed: either the toolbar disappeared, but the window would not
go fullscreen, or the toolbar disappeared in the original window, but
not in the one being fullscreen etc.

Note: when using the "Qt" (non-native) toolbar then everything works
when calling setVisible(false) before going fullscreen. But the Qt
toolbar really is no option on a Mac ;)

> Any other ideas or thoughts welcome :)

So the only idea I have left is hacking the Qt sources directly
(extending the above qcocoawindowdelegate_mac_p.h with the desired
method).


In case this is of any help or interest to someone...

Cheers, Oliver



More information about the Qt-interest-old mailing list