Make visual components non-focusable lazarus / 31-LCL ---------------------------------------------------------------------- pleumann · 2023-09-27 18:14 Hi, I have several components on the top level of my form. Some should receive focus and be navigable by tab and cursor keys (namely some TBitBtn instances) and some I would not expect to or want to receive focus (namely a TPanel and a TStaticText). The latter two are focusable, though. Not by tab, but by cursor keys. This can confuse users because the elements don't have any highlight that would indicate their focused state. How can I prevent this? I don't want set Enabled := False because I don't want the grayed-out appearance that comes with it. Best regards Joerg (FPC 3.0.2 & Lazarus 2.2.6  on Mac, Ubuntu and Raspberry Pi.) ---------------------------------------------------------------------- zeljko · 2023-09-27 18:42 TabStop := False for tabbing, probably ControlStyle := ControlStyle + [csNoFocus].... works with qt4,5,6. ---------------------------------------------------------------------- pleumann · 2023-09-27 19:08 Quote from: zeljko on September 27, 2023, 08:42:01 pmTabStop := False for tabbing, probably ControlStyle := ControlStyle + [csNoFocus].... works with qt4,5,6. TabStop is off already. I tried your snippet for everything that should not receive focus. Doesn't work. No Qt, though. MacOS native UI and GTK2 on Linux. Does it work only on Qt? Is that a bug? I mean, why should a TStaticText ever receive focus? ---------------------------------------------------------------------- KodeZwerg · 2023-09-27 22:02 1. Put in your "uses" this -> "LCLType" 2. Go to object inspector, highlight your form (Form1?) 3. activate KeyPreview = True inside properties 4. Inside "Events" go to "OnKeyDown" and doubleclick the free space to create an empty handler 5. copy and paste this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );var  NextControl: TWinControl;begin  NextControl := nil;  if (Key = VK_RIGHT) or (Key = VK_DOWN) then    NextControl := FindNextControl(ActiveControl, True, True, False);  if (Key = VK_LEFT) or (Key = VK_UP) then    NextControl := FindNextControl(ActiveControl, False, True, False);  if (NextControl <> nil) then    begin      NextControl.SetFocus;      Key := 0;    end;end;6. Run your application, now only things that have TabStop and are focusable should be valid as a target by arrow keys 7. Reply in here if this is what you wanted to achieve ---------------------------------------------------------------------- jamie · 2023-09-28 00:24 it must be a bug, it works fine on Win32/Windows, turn off tabstop and it does not tab there. Personally, I call this a bug all around that it accepts a tab operation to start with, just like the TGroupBox, tab Bug. ---------------------------------------------------------------------- KodeZwerg · 2023-09-28 08:44 Quote from: jamie on September 28, 2023, 02:24:16 amit must be a bug, it works fine on Win32/Windows, turn off tabstop and it does not tab there. Personally, I call this a bug all around that it accepts a tab operation to start with, just like the TGroupBox, tab Bug. With arrow key, at least on windows, it is a normal behavior that it try to switch to next control, no matter if focusable or not. ---------------------------------------------------------------------- pleumann · 2023-09-28 15:20 Quote from: KodeZwerg on September 28, 2023, 12:02:46 am1. Put in your "uses" this -> "LCLType" 2. Go to object inspector, highlight your form (Form1?) ... 6. Run your application, now only things that have TabStop and are focusable should be valid as a target by arrow keys 7. Reply in here if this is what you wanted to achieve I simplified your idea a bit since I have a line of buttons that are all in TabOrder, so I know which is first and which is last: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  if ((Key = VK_Up) or (Key = VK_Left)) and (ActiveControl = LanguageBtn) then    Key := 0  else if ((Key = VK_Down) or (Key = VK_Right)) and (ActiveControl = AboutBtn) then    Key := 0;end;  Interestingly, all other attempts to detect an invalid element (such as my Panel) getting selected and using ActiveControl := ... or SetFocus to jump back to the previous one failed, even if using PostMessage. The only other thing that would work was a timer checking the ActiveControl on a regular basis, but that I found somewhat ugly. Thanks! Joerg ---------------------------------------------------------------------- pleumann · 2023-09-28 15:21 Quote from: KodeZwerg on September 28, 2023, 10:44:43 amQuote from: jamie on September 28, 2023, 02:24:16 amit must be a bug, it works fine on Win32/Windows, turn off tabstop and it does not tab there. Personally, I call this a bug all around that it accepts a tab operation to start with, just like the TGroupBox, tab Bug. With arrow key, at least on windows, it is a normal behavior that it try to switch to next control, no matter if focusable or not. So it's probably behavior inherited from Windows or Delphi. Anyway, workaround does the job. I'm happy. ---------------------------------------------------------------------- zeljko · 2023-09-28 17:35 Quote from: pleumann on September 27, 2023, 09:08:20 pmQuote from: zeljko on September 27, 2023, 08:42:01 pmTabStop := False for tabbing, probably ControlStyle := ControlStyle + [csNoFocus].... works with qt4,5,6. TabStop is off already. I tried your snippet for everything that should not receive focus. Doesn't work. No Qt, though. MacOS native UI and GTK2 on Linux. Does it work only on Qt? Is that a bug? I mean, why should a TStaticText ever receive focus? csNoFocus should work on all Qt(4,5,6) controls, just tested TEdit and it works. It is bug if csNoFocus is not respected by widgetset. ---------------------------------------------------------------------- pleumann · 2023-09-28 18:20 Quote from: zeljko on September 28, 2023, 07:35:39 pmcsNoFocus should work on all Qt(4,5,6) controls, just tested TEdit and it works. It is bug if csNoFocus is not respected by widgetset. If I find the time I will check in an isolated example on Mac and Linux/GTK2. If it persists I will file a bug. ---------------------------------------------------------------------- pleumann · 2023-09-30 07:41 Can confirm the behavior exists also in a trivial new project (attached). A quick grep though the LCL source shows that only Qt and the old Carbon interface make use of csNoFocus at all. Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i bash-3.2$ pwd/Users/joerg/Temp/lazarus/lcl/interfacesbash-3.2$ egrep -r csNoFocus *carbon/carbonproc.pp:  if not (csNoFocus in ControlStyle) thencarbon/carbonprivate.pp:    AStyle := AStyle + [csNoFocus];qt/qtwidgets.pas:       (csNoFocus in LCLObject.ControlStyle)qt/qtwidgets.pas:      if (csNoFocus in LCLObject.ControlStyle) thenqt/qtwsforms.pp:    if (csNoFocus in TCustomForm(AWidget.LCLObject).ControlStyle) thenqt5/qtwidgets.pas:     (csNoFocus in LCLObject.ControlStyle)qt5/qtwidgets.pas:      if (csNoFocus in LCLObject.ControlStyle) thenqt5/qtwsforms.pp:    if (csNoFocus in TCustomForm(AWidget.LCLObject).ControlStyle) then  Is it worth filing a bug? ---------------------------------------------------------------------- sstvmaster · 2023-09-30 21:37 Relates to? https://gitlab.com/freepascal.org/lazarus/lazarus/- /issues/0024735#note_638000734