New in 4.3: Unified title and toolbar on Mac OS X

Posted by Trenton Schulz on March 11, 2007 · 16 comments

Well, we are closing in on 4.3 and it looks like it is shaping up to be a good release. Of course, this is what I usually think with every release. Anyway, since I usually talk about “Mac things,” I thought I would take this opportunity to show off something that seems to caused a bit of a local stir at work, Mac OS X unified toolbars.

If you are running Mac OS X 10.4 or higher (Tiger if you think in cats), you have seen that many applications have there toolbars blending right into the title bar. You probably were wondering, “How did they do that?” Probably followed up by a “how can I do that in Qt?”

Well, with 4.2, it was possible to do (though you would have to write a fair amount of code). That’s usually enough to make a programmer reconsider the endeavor. With Qt 4.3, though, we’ve made it fairly easy. Simply create your QMainWindow and toolbars as normal. Then take a look at the QMainWindow::setUnifiedTitleAndToolBarOnMac() property. This will put all the toolbars in the top toolbar area and does the magic to blend the toolbars into the title bar. It’s that simple!

So, how does it look? Well, we added it to Assistant. The before and after picture are below, take a look:

Picture of Qt Assistant from Qt 4.2 with classic toolbars and Qt Assistant in Qt 4.3 with toolbars unified with the title bar

If you want to take a look at this in the snapshots and provide feedback, please do. Don’t report that the window doesn’t stay in the same spot the next time you open the application, though. We are already aware of that issue and are working on it.

QShare(this)

Possibly related posts:

  1. Qt Assistant compat version available as extra source package
  2. Gestures in 4.7.1 behavior change

16 comments

1 Bill King March 12, 2007 at 2:43 am
 

Something that came up while discussing this with a friend:

Should this be just for mac? For example, if someone wants to emulate the mac look on windows (ala itunes), should this be allowed on non-mac systems?

2 qtusernamegoeshere March 12, 2007 at 4:17 am
 

Lovely! Thank you soooo much!

3 Anonymous March 12, 2007 at 8:22 am
 

setUnifiedTitleAndToolBarOnMac doesn’t sound like a stellar property name. Why not skip the “OnMac” part? Just document that it does not apply on any other platform.

4 Remko Tronçon March 12, 2007 at 9:04 am
 

Can you embed other widgets in the toolbar as well?

5 girish March 12, 2007 at 11:31 am
 

> Can you embed other widgets in the toolbar as well?

Yes, use QWidgetAction.

6 trenton March 12, 2007 at 11:35 am
 

For the moment this is Mac only since it’s some magic that the window manager does and nothing that we can do other than follow Carbon’s rules for this. That’s why internally we move the QToolBars into a HIToolbar (yes, small ‘b’ there). If there was a way that you could blend the titlebar in other window managers with the window contents, then it would be possible. It might be possible in Windows (haven’t looked), though I think it may be impossible on X11 unless you are wrting the window manager as well.

As for embedding other widgets, you can simply add you widgets to a QToolbar and everything should work OK. However if the toolbar shrinks to be too small to show the widget, you won’t be able to access the widget. On a side note, that’s as well as HIToolbar supports custom widgets itself.

7 Alexander K. March 12, 2007 at 4:42 pm
 

Hello,
this is wonderful. But I have a question kinda regarding this.
In Windows Vista alot of the included applications have their tool bars or some widgets in general within the actual glass frame (like the address bar and the back-buttons in Explorer or just the entire client area is “transparent”, i.e. it’s like part of the glass frame). So will this be possible somehow at all with Qt 4.3 or maybe in some future release? Maybe like setting the window palette of the mainwindow would do the trick so it’s backwards compatible with XP/98/Mac/KDE/etc.
This is really interesting me and I’d be glad to have an answer to this.

8 trenton March 12, 2007 at 5:03 pm
 

As far as something for other platfroms, this is a special Mac OS X window manager hack. We have to play by their rules in order for the toolbar to work correctly. Therefore it’s kind of hard to make this work on other platforms. On X11, for example, I doubt we would have any influence on how the window is drawn, only if we actually said the window was frameless and “faked” a frame. This would not look very X11-native :)

9 girish March 12, 2007 at 5:45 pm
 

> So will this be possible somehow at all with Qt 4.3 or maybe in some future release?

There is no public API. But you can have a look at qwizard_win.cpp in the 4.3 snapshots where we increase the size of the non-client area and put stuff there.

10 Alexander K. March 12, 2007 at 6:57 pm
 

Well, that does seem promising! Thank you.
Will it also be possible to disable the “Insert Unicode Control Character” in the context menues of QLineEdits and similar input widgets? Or maybe you could consider such a function because currently they seem to be hard coded into Qt :(

11 Jay Miller March 12, 2007 at 10:01 pm
 

Given the example you mention in qwizard_win.cpp, perhaps it would be best to keep the API call as QMainWindow::setUnifiedTitleAndToolBar(), even if it is only supported on Mac for now with an eye toward it being able to move toolbars into the non-client area in the future. I know I would like for my top area toolbars to move up if the Aero theme is in use.

12 Jay Miller March 12, 2007 at 10:06 pm
 

Perhaps given the example of QWizard the API should just be QMainWindow::setUnifiedTitleAndToolBar() even if it is only supported on the Mac for now with an eye toward making it available on other platforms in the future. I know I would like for my top area toolbars to be moved into the non-client area if the Aero theme is in use.

13 trenton March 13, 2007 at 12:19 pm
 

Now that I’m no longer being marked as a spammer…

Please don’t put requests for other Qt classes (like QLineEdit) here. You should rather file them through an official channel:

http://www.trolltech.com/bugreport-form
Regarding the name of the property. We decided we would put “Mac” in it because it would give a clue to people using it that it would only work on Mac OS X. Then hopefully people wouldn’t call the property and claim that nothing happens on the other platforms. If we eventually offer something like this on the other platforms, we can obsolete this property in favor of the new one.

14 Alexander K. March 13, 2007 at 3:29 pm
 

Well, I personally think it would be a really good approach to make something available to the Vista users so developers can put their widgets in the top glass frame or in the bottom like Windows Media Player does.
To make it more platform-independent you could just “resize” that client area only in Vista and in other Windows versions and OSs it would just put everything within the frame. Of course this “resizing” would need to be enabled first somehow or something.
This would definitely be a really good approach towards the new Vista controls.

15 Adam Higerd March 14, 2007 at 1:35 pm
 

So does it break ABI or something to add another WindowFlag?

16 Steven Fisher March 16, 2007 at 1:22 am
 

Looks gorgeous. I wasn’t too happy with toolbars in Qt 4.2 since the background color is too dark, but this post means I’ll stop hacking at that and just bear it until 4.3. :)

Comments on this entry are closed.

Previous post:

Next post: