Recent

Author Topic: How to really prevent a control from losing focus?  (Read 1869 times)

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to really prevent a control from losing focus?
« Reply #15 on: November 11, 2024, 02:42:56 pm »
On the other hand I would considers this a serious matter on both Gtk2 and Qt5, since that ButtonClick should not be possible at all. Looks like Windows is the only reliable platform here - and I always thought focus issues were a mess there.
Yes. qt5/Linux almost worked but the fact that the Button1Click 'bleeds' through when focus is prevented is indeed a serious issue.

I haven't had the chance yet to test qt5 on Windows.

If you think it's but please open an issue against qt5/qt6. Qt probably sends Clicked() signal and we are processing it without check if button is focused (of course must check if clicked() comes from mouse event, not from eg shortcut).

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to really prevent a control from losing focus?
« Reply #17 on: November 11, 2024, 06:08:05 pm »
Fixed, you can test qt5 and qt6 :)

Sieben

  • Sr. Member
  • ****
  • Posts: 363
Re: How to really prevent a control from losing focus?
« Reply #18 on: November 14, 2024, 11:22:31 am »
Thanks a lot, zeljko. rvk, could you please have a look...? And I want to remind everyone that possible workarounds for Gtk2 are mentioned at the bottom of page 1 of this thread.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to really prevent a control from losing focus?
« Reply #19 on: November 14, 2024, 12:25:47 pm »
Just a few remarks on possible workarounds (and to keep this topic floating): you can reliably prevent the Button1Click handler to be executed by placing this right at the top of it's code:

Code: Pascal  [Select][+][-]
  1.   {$ifdef LCLGtk2}
  2.   if not Button1.Focused then Exit;
  3.   {$endif}  
  4.  

and you can make the SelectAll of Edit2 (all this refers to the test project included above) work by inserting this between SetFocus and SelectAll:

Code: Pascal  [Select][+][-]
  1.   Edit2.SetFocus;
  2.   {$ifdef LCLGtk2}
  3.   Application.ProcessMessages;
  4.   {$endif}
  5.   Edit2.SelectAll;  
  6.  

I did not test with Qt5 so far.

Since qt5/qt6 is fixed, please open an issue against gtk2 and attach example project.

 

TinyPortal © 2005-2018