trenton
Qt
Posted by trenton
 in Qt
 on Sunday, March 11, 2007 @ 21:39

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.

16 Responses to “New in 4.3: Unified title and toolbar on Mac OS X”

» Posted by Bill King
 on Monday, March 12, 2007 @ 01:43

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?

» Posted by qtusernamegoeshere
 on Monday, March 12, 2007 @ 03:17

Lovely! Thank you soooo much!

» Posted by Anonymous
 on Monday, March 12, 2007 @ 07:22

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.

» Posted by Remko Tronçon
 on Monday, March 12, 2007 @ 08:04

Can you embed other widgets in the toolbar as well?

» Posted by girish
 on Monday, March 12, 2007 @ 10:31

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

Yes, use QWidgetAction.

» Reply from trenton
 on Monday, March 12, 2007 @ 10:35

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.

» Posted by Alexander K.
 on Monday, March 12, 2007 @ 15:42

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.

» Reply from trenton
 on Monday, March 12, 2007 @ 16:03

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 :)

» Posted by girish
 on Monday, March 12, 2007 @ 16:45

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

» Posted by Alexander K.
 on Monday, March 12, 2007 @ 17:57

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 :(

» Posted by Jay Miller
 on Monday, March 12, 2007 @ 21:01

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.

» Posted by Jay Miller
 on Monday, March 12, 2007 @ 21:06

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.

» Reply from trenton
 on Tuesday, March 13, 2007 @ 11:19

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.

» Posted by Alexander K.
 on Tuesday, March 13, 2007 @ 14:29

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.

» Posted by Adam Higerd
 on Wednesday, March 14, 2007 @ 12:35

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

» Posted by Steven Fisher
 on Friday, March 16, 2007 @ 00:22

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



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.