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. Focus rectangles macOS
Qt 6.11 is out! See what's new in the release blog

Focus rectangles macOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 781 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.
  • B Offline
    B Offline
    brkonator
    wrote on last edited by
    #1

    Hi, this is quite a common problem I guess, but I can't seem to find any "standard" solution to this. I'm developing a cross-platform library (macOS/Windows) which dynamically loads UI files using a subclassed QUiLoader.

    1st part of the question: I created some sample .ui files on Windows, and when the files are loaded and application is shown, everything is just like I designed it. But on macOS, there needs to be an extra space for some controls (especially those, which are focusable) for them to be able to show a focus rectangle properly.

    E.g. for QPushButton (111x23px):

    1. Windows - OK button is nicely shown, focus rectangle as well
      2aef9a7b-8fc5-487a-8a21-25db96a9028e-image.png

    2. macOS - button and focus rectangle are not fully shown - not enough space
      3ea0b5f1-4758-40ce-a898-1cae60c0fc13-image.png

    If I make the button 31px high, it's okay on macOS but it's too big on Windows. The same applies to QComboBox and other controls. I know, that this can be solved by using different .ui files for different control but I would like to do it using 1 .ui file. Do I have to dynamically change the button's height in the code if I'm on the Windows platform or is there a better solution?

    2nd part of the question - also regarding focus rectangle on macOS. QCheckBox seems to have a problem showing its focus rectangle and it doesn't matter how big it is. It only shows some weird dot in the top-left corner:
    6308e1b4-8847-47b0-8773-614f71601aaf-image.png

    Native macOS checkboxes show the focus rectangle like this:
    07be2a33-216e-4dda-99ab-fc2c7c8b98d2-image.png

    I'm using Qt 5.12.9, Windows 10, and macOS 10.15.6 (but both problems were valid also on Qt 5.14.1 and older macOS versions). Thanks in advance.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Don't hardcode sizes. Even if it looks correct on some platform there's no guarantee there won't be an OS update that changes some sizes or effects and your ui will break. Hardcoding sizes can also lead to broken ui on monitors with different scaling factor than yours. Use layouts to manage widget placement and sizes. They take care of platform differences for you.

      B 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        Don't hardcode sizes. Even if it looks correct on some platform there's no guarantee there won't be an OS update that changes some sizes or effects and your ui will break. Hardcoding sizes can also lead to broken ui on monitors with different scaling factor than yours. Use layouts to manage widget placement and sizes. They take care of platform differences for you.

        B Offline
        B Offline
        brkonator
        wrote on last edited by
        #3

        @Chris-Kawa This is a problem since I'm working on the library that wraps also frameworks other than Qt and some of them don't support dynamic layouts - and I don't really have time to implement that support myself. Hard-coded positions and sizes are enough for now. I guess I will have to do it using macros from withing the code and change the size there. I just have to find a reasonable way, because buttons with a larger height could be desired in some places - in others, they should be of standard height - cca 21px in Windows. And how about the checkbox focus rectangle issue, has anybody encountered this?

        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