In OS X QPushButton spontaneously changes style when width is less than 50 pixels
I'm building an OS X application using Qt 5.3.2, and in it I want to have a standard QPushButton with a size of 40x32. Normally in OS X a QPushButton without any custom style sheet appears in the same style as most OS X buttons, specifically the Cocoa "NSRoundedBezelStyle". When adjusting its size, however, Qt may automatically select a new Cocoa button style. Setting its height to something larger than 32 causes it to switch to the "NSShadowlessSquareBezelStyle", and setting its width to less than 50 does the same.
So I'm stuck in an annoying situation. I want a QPushButton that uses the NSRoundedBezelStyle, but I want its size to be 40x32. Qt automatically changes the style to NSShadowlessSquareBezelStyle.
Is there anyway I can prevent it from doing that?
Things I've tried:
Getting the underlying Cocoa object using the winId() function in the hopes it exposes an NSButton, but it's of type QNSView and doesn't give me any way of accessing an NSButton instance.
Using a custom style sheet to make it look like an OS X button. It's almost possible, but it looks crappy, and the look and behavior of OS X buttons changes between system versions, especially between 10.9 and 10.10. I really need to just have it use the default appearance without me trying to recreate it.
Thanks in advance!
There is no NSButton, only a view that behaves and looks like a button. It is draw with the Appearance Manager so that it matches the current OS look.
It looks like this behaviour is hardcoded in Qt, see:
qmacstyle_mac.mm, line 1299 in Qt 5.4.0
Not much you can do.
-change Qt's source
-write your own button widget that draw itself with the Appearance Manager but without this limitation.