Recent

Author Topic: Edit changes color after being disabled then enabled  (Read 5569 times)

TheMouseAUS

  • Full Member
  • ***
  • Posts: 107
Edit changes color after being disabled then enabled
« on: August 28, 2023, 08:31:26 pm »
I have noticed behavior I dont think is right. If I change the color of a TEdit to say black with lime green text, it displays fine. If the component gets disabled and then enabled the color is back to form default (white) with the text still Lime green. I have too many edits on my form to code  each one back to black again after being enabled. Is this behavior correct? Any ideas for a work around? Thanks :-)

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #1 on: August 28, 2023, 10:43:41 pm »
Open an issue please and attach example project. Also write Lazarus version and which qt widgetset do you use (4,5 or 6).

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Edit changes color after being disabled then enabled
« Reply #2 on: August 29, 2023, 12:13:39 am »
Any ideas for a work around? Thanks :-)
For your enable event:
Code: Pascal  [Select][+][-]
  1. var
  2.   i: Integer;
  3. begin
  4.   for i := 0 to Pred(ComponentCount) do
  5.     if (Components[i] is TEdit) then
  6.       begin
  7.         (Components[i] as TEdit).Color := clBlack;
  8.         (Components[i] as TEdit).Font.Color := clLime;
  9.       end;
  10. end;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

TheMouseAUS

  • Full Member
  • ***
  • Posts: 107
Re: Edit changes color after being disabled then enabled
« Reply #3 on: August 29, 2023, 09:03:47 pm »
Open an issue please and attach example project. Also write Lazarus version and which qt widgetset do you use (4,5 or 6).

I am using Lazarus 2.2.6/ FPC 3.2.2
Fedora 38 X64
QT5

I decided to create a bug report https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40471

To test just drop a TEdit and a button on a form.
Change the color of the Edit
Have the button have to toggle the edits enable

I did notice this behavior about 6 months back but kept forgetting to report it.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if edit1.enabled then edit1.Enabled := false else edit1.enabled := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  edit1.color := clBlack;
end;


TheMouseAUS

  • Full Member
  • ***
  • Posts: 107
Re: Edit changes color after being disabled then enabled
« Reply #4 on: August 31, 2023, 10:47:16 am »
Thanks for the suggestion, only I have discovered that once either a Tedit or Tmemo has been disabled and then enabled I cannot set its color at all, just stays white.

Any ideas for a work around? Thanks :-)
For your enable event:

Code: Pascal  [Select][+][-]
  1. var
  2.   i: Integer;
  3. begin
  4.   for i := 0 to Pred(ComponentCount) do
  5.     if (Components[i] is TEdit) then
  6.       begin
  7.         (Components[i] as TEdit).Color := clBlack;
  8.         (Components[i] as TEdit).Font.Color := clLime;
  9.       end;
  10. end;

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #5 on: August 31, 2023, 01:44:32 pm »
Thanks for the suggestion, only I have discovered that once either a Tedit or Tmemo has been disabled and then enabled I cannot set its color at all, just stays white.

Any ideas for a work around? Thanks :-)
For your enable event:

Code: Pascal  [Select][+][-]
  1. var
  2.   i: Integer;
  3. begin
  4.   for i := 0 to Pred(ComponentCount) do
  5.     if (Components[i] is TEdit) then
  6.       begin
  7.         (Components[i] as TEdit).Color := clBlack;
  8.         (Components[i] as TEdit).Font.Color := clLime;
  9.       end;
  10. end;

Better would be to create simple project example with your problem and attach it to the issue, so I can easy reproduce and fix it.
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40471

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Edit changes color after being disabled then enabled
« Reply #6 on: August 31, 2023, 02:06:59 pm »
I would write this
procedure TForm1.Button1Click(Sender: TObject);
begin
  if edit1.enabled then edit1.Enabled := false else edit1.enabled := true;
end;
like that:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   edit1.enabled := not edit1.enabled;
  4. end;
But it has nothing to do with your actual problem, just saying :)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

VisualLab

  • Hero Member
  • *****
  • Posts: 729
Re: Edit changes color after being disabled then enabled
« Reply #7 on: August 31, 2023, 06:14:29 pm »
I have noticed behavior I dont think is right. If I change the color of a TEdit to say black with lime green text, it displays fine. If the component gets disabled and then enabled the color is back to form default (white) with the text still Lime green. I have too many edits on my form to code  each one back to black again after being enabled. Is this behavior correct? Any ideas for a work around? Thanks :-)

I have prepared an example of a simple project consisting of a window (TForm) on which I placed an edit box (TEdit) and a check box (TCheckBox). Here is the example code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.   {TForm1}
  12.   TForm1 = class(TForm)
  13.     CheckBox1: TCheckBox;
  14.     Edit1: TEdit;
  15.     procedure Button1Click(Sender: TObject);
  16.     procedure CheckBox1Change(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.lfm}
  26.  
  27. {TForm1}
  28.  
  29. procedure TForm1.CheckBox1Change(Sender: TObject);
  30. begin
  31.   Edit1.Enabled := CheckBox1.Checked;
  32. end;
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. begin
  36.   Edit1.Enabled := not Edit1.Enabled;
  37. end;
  38.  
  39. procedure TForm1.FormCreate(Sender: TObject);
  40. begin
  41.   CheckBox1.Checked := True;
  42. end;
  43.  
  44. end.

I used Lazarus 2.2.4 to create the project. I compiled the project under Windows 10. I ran the project. The program behaves correctly during operation, i.e. the edit field permanently maintains the background and font color set at the design stage, both when it is active (property Enable = True) and when it is inactive (property Enable = False). It's similar in the design phase when I change properties in the Object Inspector. In conclusion, I do not confirm the reported bug in Lazarus 2.2.4 and Windows 10.

---

Edit: I added a button (TButton) to the project. I've supplemented the attached code with a button click procedure. This change also does not cause the edit field to behave incorrectly (i.e. the edit field behaves correctly).
« Last Edit: August 31, 2023, 06:19:19 pm by VisualLab »

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #8 on: August 31, 2023, 06:29:51 pm »
Nobody mentioned win32 ws byt qt5, issue is opened against qt5 and it' confirmed.

VisualLab

  • Hero Member
  • *****
  • Posts: 729
Re: Edit changes color after being disabled then enabled
« Reply #9 on: August 31, 2023, 06:38:49 pm »
Nobody mentioned win32 ws byt qt5, issue is opened against qt5 and it' confirmed.

Forgot to add: Windows 10 64-bit. Also, now I've done a test on Linux Kubuntu 23.04 (Qt 5.18.8, X11) with Lazarus 2.2.6. The described problem with TEdit also does not occur here.
« Last Edit: August 31, 2023, 08:18:56 pm by VisualLab »

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #10 on: August 31, 2023, 08:37:48 pm »
What widgetset Lazarus uses ? gtk2 or qt(4,5,6) ?

VisualLab

  • Hero Member
  • *****
  • Posts: 729
Re: Edit changes color after being disabled then enabled
« Reply #11 on: September 01, 2023, 06:39:13 pm »
What widgetset Lazarus uses ? gtk2 or qt(4,5,6) ?

Indeed, I did not check the widget set. The project was set to the default widget set, which is: Gtk2. I changed the set of Qt5 widgets in the project options. Unfortunately, when compiling, Lazarus reports the following message:

Code: [Select]
Warning: linker: /usr/bin/ld: cannot find -lQt5Pas: No such file or directory
Error: Error while linking

The directory /usr/lib/x86_64-linux-gnu contains the library libQt5Pas.so.1.2.9 and the symlink to it libQt5Pas.so.1. So far, uncle Google hasn't suggested anything useful, so I don't feel like "poking around in the system" to solve it. I don't need it urgently at the moment.

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #12 on: September 01, 2023, 07:14:17 pm »
You must install libQt5Pas-dev package to build lazarus qt5 apps, or lazarus itself.
If you cannot install it for any reason then
try sudo ln -s /usr/lib/x86_64-linux-gnu/libQt5Pas.so.1.2.9 /usr/lib/x86_64-linux-gnu/libQt5Pas.so
Now try to build.

VisualLab

  • Hero Member
  • *****
  • Posts: 729
Re: Edit changes color after being disabled then enabled
« Reply #13 on: September 01, 2023, 10:20:45 pm »
You must install libQt5Pas-dev package to build lazarus qt5 apps, or lazarus itself.
If you cannot install it for any reason then
try sudo ln -s /usr/lib/x86_64-linux-gnu/libQt5Pas.so.1.2.9 /usr/lib/x86_64-linux-gnu/libQt5Pas.so
Now try to build.

Thanks for the hint. There was a symlink: libQt5Pas.so.1. However, the symlink was missing: libQt5Pas.so. After creating it, Lazarus generated the executable for the Qt5 widget set without any problems.

Indeed, there is a problem with the edit box (TEdit), i.e. after changing its property Enabled from False to True, the color is set to white even though black was set at the design stage. Interestingly, this only happens for black (I checked a few other colors).

zeljko

  • Hero Member
  • *****
  • Posts: 1920
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Edit changes color after being disabled then enabled
« Reply #14 on: September 02, 2023, 09:50:06 am »
Try patch from related issue, it works.

 

TinyPortal © 2005-2018