Mac widget style addons

Posted by Morten Johan Sørvig on April 17, 2009 · 11 comments

cocoawidgets.png

Qt on Mac OS X has traditionally used Appearance Manager/HITheme to draw its widgets. This has been a great experience so far, but lately more and more UI elements have appeared as Cocoa views only with no corresponding HITheme API.

So, for Qt 4.5 we went ahead and built an escape hatch: QMacCocoaViewContainer. This class allows you to embed any Cocoa view in a Qt widget hierarchy. Its only drawback is that programmers have to learn the Cocoa API conventions and that odd [function call] syntax.

To try to remedy this I’ve experimented a bit with using the Cocoa views (or Cocoa cells to be specific) directly to replace the drawing code for certain widgets. So far I’ve done three classes: QtCocoaPushButton, QtCocoaComboBox and QtCocoaSegmentedButton. The first two are subclasses of the similar Qt classes, while the last provides a visual appearance for QButtonGroup.

I’m currently supporting my dev machine setup: Qt 4.5/Cocoa on Mac OS X.5.
Qt 4.4, Qt/Carbon or 10.4 support can probably be added if there is interest.

The code is available on the git server (Run “git clone git://labs.trolltech.com/msorvigs-cocoawidgets cocoawidgets”)

QShare(this)

Possibly related posts:

  1. Alien widgets on Mac
  2. Qt 4.7.0 Beta1
  3. Qt 4.7.0 Release Candidate available

11 comments

1 Aurélien Gâteau April 17, 2009 at 1:39 pm
 

I would love to be able to use segmented buttons in any Qt/KDE app. Would it be possible to add them to the Qt API?
I implemented an ersatz of them for Gwenview zoom buttons in the status bar, but it does not look nice with all styles.

2 naresh April 17, 2009 at 1:41 pm
 

Mac OS X 10.4 support would be realy great… It’s realy hard to drop 10.4 support in these days…

3 Morten April 17, 2009 at 1:59 pm
 

Aurélien: I don’t think there are any concrete plans for cross-platform segmented buttons, but I’ll forward your request to the appropriate team.

4 Will Stokes April 17, 2009 at 3:12 pm
 

This is most exciting, but I would need 10.4/Carbon support as well. I would also appreciate being able to create those native help buttons and segment buttons in a cross platform manner as well. What would be idea is if Qt developers could apply standard styles to their widgets like this in a semi-cross platform manner.

5 Reed April 17, 2009 at 3:53 pm
 

I was just about to make a similar inquiry…!

6 Qtuser April 17, 2009 at 4:06 pm
 

Wonderful!

I would only vote for Qt 4.4 support, but I am prob. moving to Cocoa 4.5 next month so….

oh and as for 10.4 support, Every metric I have seen of active users and buyers shows that people that actually pay for software, have moved on to 10.5 are in the 70% – 80% range. Of course it depends on your exact market, but really, with 10.5 snow leopard coming out creating another platform to test on, 10.4 support for this specific thing really needs to be thought about before proceeding IMO.

7 Freddie Witherden April 18, 2009 at 11:22 am
 

I agree that a general segmented button control would be very neat indeed — and something which I would make use of in my applications.

Cool example, though.

8 Bruce April 20, 2009 at 7:34 am
 

++Cross-platform segmented buttons! My experimental workaround is ugly inside and out.

9 Rens de Nobel April 22, 2009 at 11:27 pm
 

Wooot ! This is excellent, I’ve been spending time already on mimicking the MacOS native UI controls with styles and graphics. That works okay, but this is way better of course. Now only to continue my quest to get a proper GIT client for MacOS …. any ideas ?

11 Rens de Nobel April 30, 2009 at 1:12 pm
 

Morten, I get this error when I run a clean build :
cocoawidgets.mm: In function ‘void paintCell(NSCell*, QWidget*)’:
cocoawidgets.mm:64: error: cannot convert ‘OpaqueControlRef*’ to ‘NSView*’ in argument passing

Comments on this entry are closed.

Previous post:

Next post: