Remove focus ring on a Segmented control?

Latest version of both.
It only happens on one segmented control - all the others are fine?

Richard, open System Preferences -> Keyboard -> Shortcuts. Then check to see if full keyboard access is set to “Text boxes and lists only” or “All controls”. If it is set to all controls that will explain why your segmented controls have focus and everyone else’s don’t. The default setting is “Text boxes and lists only”.

Ah! This way I could reconstruct it. Thanks, Jason!

If you need to keep the setting but don‘t want the focusring, here‘s a short subclass:

Segmented Control With FocusRing Property

It’s set to “Text Boxes and lists”. :frowning:

And does it change when you add a

#if targetmacos declare sub setFocusRingType lib "Cocoa.framework" selector "setFocusRingType:" (id as integer, value as Integer) setFocusRingType (me.handle, 1) #endif
to the open event of the Control?

(0 = default, 1 = none, 2 = exterior (which usually doesn‘t look any different)

This is all I have in the Window Open event:

// REMOVE THE FOCUS FROM ALL CONTROLS ClearFocus

I will put the code above in the open event - but the glow only appears occasionally - not every time the app is built.
That is what is so confusing.

When I add this code:

#if targetmacos declare sub setFocusRingType lib "Cocoa.framework" selector "setFocusRingType:" (id as integer, value as Integer) setFocusRingType (me.handle, 1) #endif

Do I need to any any properties etc to my window?

Thanks.

No, nothing to add. This is the shortcut to the subclass above. It simply removes the focusring from the control you place it in – preferably its open event. As long as the control inherits from Cocoa.NSView, and that is almost everything from Rectangle on upwards.

Properties like in the subclass would only be needed if you want to switch the focusring on again in some situations. In that case, add the computed property from the subclass and the enumeration to any control or class you‘d like to use that on. You could then switch the focusring‘s visibility from anyhwere in your code by calling the set method.

I will know if it worked after I have built and run my app another 20 times. If it hasn’t appeared by then - I will know it has worked :slight_smile:
Thanks Ulrich - much appreciated.

I keep my fingers crossed. I had a similar thing on an ImageWell that wanted to show a FocusRing no matter what I tried. It hasn‘t since I introduced the method to it :wink:

My 2 cents:

If you only have buttons, you can set TabStop to OFF and obviously the focus ring disappear.

BUT… some controls, like the Segmented, does not have TabStop (and I use it a lot, I love it).

I used to write a workaround in OS X BEFORE Yosemite, to get rid of the Focus ring completely. For some reason in Yosemite all my focus ring problems went out. But now I installed the 10.10.2 Beta and the focus ring nightmare is back.

Clearfocus does not seems to work, I tried in the Open() of the control and the window. No results, BUT…

You can SHOW the window, even if it is the active one, and then clearfocus. That works.

windowName.Show
ClearFocus

Last, I tend to use a Clearfocus call in the Activate() event of the window. That way, when it is minimized and restored, or another window comes on top of it, the focus remain cleared.

I believe the problem is you can’t say the SegmentedControl to not get focus on tab via IDE (Tabstop switch missing in the panel).

You can implement the Open event and set

me.Tabstop = false

I’ll try it later Massimo thanks

No. (me.Tabstop = false) Not working.

I insist, it worked on Yosemite, but NOT in Yosemite 10.10.2 beta

[quote=154460:@Lisandro Mulena]

No. (me.Tabstop = false) Not working.

I insist, it worked on Yosemite, but NOT in Yosemite 10.10.2 beta[/quote]

What about setting the focus to a control out of the window area ? It does get the focus out of the visible sc.

Yeah, there are several valid approaches, setting the focus to a dummy control and set visibility to false…

…but I think the cleanest way is the (windowName.Show + ClearFocus) workaround, luckily it still works.

[quote=154498:@Lisandro Mulena]Yeah, there are several valid approaches, setting the focus to a dummy control and set visibility to false…

…but I think the cleanest way is the (windowName.Show + ClearFocus) workaround, luckily it still works.[/quote]

I thought you said it no longer worked in 10.10.2 ?

Well…

Sorry for my english. Tabstop and Clearfocus don’t work in 10.10.2, the workaround still works.

I’ve suddenly developed this problem as well.
I’m running OS X 10.10.4 and Xojo 2015v2.2.
I have a window with 4 checkboxes and converted them to a multi select segmented control.
When I open the window the first selected segment has a focus ring round it. I hate focus rings with a vengeance and
always turn it off unless there’s a overriding reason to keep it (usually there isn’t!).
The question is, why did this suddenly appear; focus ring is not a property of a segmented control.
Full keyboard control is set to text and listboxes only so that’s not the problem. I did include the conditional code suggested above
and that appears to have sorted the problem, but I don’t understand why it was necessary in the first place. I’ve replaced a few
button combinations, particularly radio buttons, to segmented controls and never had this problem before.
Any ideas anyone?

Thanks
Jack

Sorry for bumping an old thread but I ran into the same issue.
When I place a 1 item segmented control and nothing else, it has the blue focus ring and I can’t find a way to disable it.

Ulrich’s declare in the .Open event gives me an ObjCException: “-[XOJWindow setFocusRingType:]: unrecognized selector sent to instance 0x1678f20”

Does anyone know a way to disable the focus ring?