Recent

Author Topic: Focus return does not work  (Read 635 times)

7bit

  • New Member
  • *
  • Posts: 15
Focus return does not work
« on: February 16, 2025, 07:24:06 am »
I want to show the window and return the focus to the input field, but it doesn't work. The focus is still on the window. This is the behavior of the QT 5/6 widgets (and GTK2 even without PopupParent). Everything works with win32 widgets in windows. Here is my code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Form2.PopupParent := Self;
  4.   Form2.Show;
  5.   Edit1.SetFocus;
  6. end;
  7.  
« Last Edit: February 16, 2025, 07:25:45 am by 7bit »

zeljko

  • Hero Member
  • *****
  • Posts: 1723
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Focus return does not work
« Reply #1 on: February 16, 2025, 08:45:59 am »
hmmm...that should work with qt5/qt6

7bit

  • New Member
  • *
  • Posts: 15
Re: Focus return does not work
« Reply #2 on: February 16, 2025, 04:34:40 pm »
I forgot to write my configuration: Lazarus 4.0RC2 (rev lazarus_4_0RC2-104-gb0513d9031) FPC 3.2.2 x86_64-linux-gtk2 (with changes https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/a8b242d65106ea3b3d93c5734755f58dc6089ca9), Alt Workstation 10.4 (Mate Desktop).

zeljko

  • Hero Member
  • *****
  • Posts: 1723
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Focus return does not work
« Reply #3 on: February 16, 2025, 06:56:53 pm »
Ok , so, if popupparent isn't setted up it works for qt5 and qt6 ? That's pretty strange

7bit

  • New Member
  • *
  • Posts: 15
Re: Focus return does not work
« Reply #4 on: February 16, 2025, 08:03:45 pm »
It doesn't work anyway.

zeljko

  • Hero Member
  • *****
  • Posts: 1723
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Focus return does not work
« Reply #5 on: February 16, 2025, 08:43:47 pm »
Please open an issue at lazarus bugtracker in that case. Attach small example project, and write detailed info about lazarus version, installed qt libs on system, window manager etc.

dsiders

  • Hero Member
  • *****
  • Posts: 1377
Re: Focus return does not work
« Reply #6 on: February 16, 2025, 10:10:54 pm »
IMO, we're missing some information exchange here.

The OP is not describing why he thinks it doesn't work. And I'm not sure I even understand anymore the way it is supposed to work.

When I try his code, Form2.Show causes the form to become not only visible but also to have focus. So neither Form1 nor Edit1 have focus. Edit1.SetFocus doesn't force focus to return to Form1 and Edit1 is not focused as a result. Should the form and control be focused? When I change focus to Form1 by clicking on its Title bar - Edit1 does in fact have focus.

So either his expectations are wrong (that set focus causes the parent form to be focused) or the SetFocus code is wrong.
« Last Edit: February 16, 2025, 10:18:23 pm by dsiders »
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

7bit

  • New Member
  • *
  • Posts: 15
Re: Focus return does not work
« Reply #7 on: February 17, 2025, 06:49:15 am »
When I try his code, Form2.Show causes the form to become not only visible but also to have focus. So neither Form1 nor Edit1 have focus. Edit1.SetFocus doesn't force focus to return to Form1 and Edit1 is not focused as a result.
That's the problem.

Should the form and control be focused?
Yes.


7bit

  • New Member
  • *
  • Posts: 15
Re: Focus return does not work
« Reply #8 on: February 17, 2025, 06:51:34 am »
Please open an issue at lazarus bugtracker in that case. Attach small example project, and write detailed info about lazarus version, installed qt libs on system, window manager etc.
Ok.

zeljko

  • Hero Member
  • *****
  • Posts: 1723
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Focus return does not work
« Reply #9 on: February 17, 2025, 11:10:31 am »
Hm...problem is that when you setFocus to Edit1, WS actually sets focus, but stringgrid imediatelly grabs focus back.

 

TinyPortal © 2005-2018