Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In OS X QPushButton spontaneously changes style when width is less than 50 pixels
Forum Updated to NodeBB v4.3 + New Features

In OS X QPushButton spontaneously changes style when width is less than 50 pixels

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 904 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Guy GizmoG Offline
    Guy GizmoG Offline
    Guy Gizmo
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sandy.martel
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved