[Lazarus] How to limit editor area of a TEdit

zeljko zeljko at holobit.net
Mon Feb 2 15:13:13 CET 2015


On 02/02/2015 02:56 PM, Gabor Boros wrote:
> 2015.02.02. 14:09 keltezéssel, zeljko írta:
>> On 02/02/2015 01:46 PM, Gabor Boros wrote:
>>> Hi,
>>>
>>> I want to include a control in a TEdit. On Windows can decrease the
>>> editor rectangle with EM_SETRECT message. Any similar feature is exist
>>> in Qt or a multi platform solution?
>>
>> In Qt yes, others like gtk2 no.
>> I've created and edit with button inside and it works (qt).
>> This should work:
>> EditBitBtn := TBitBtn.Create(Self{TMyEdit})
>> EditBitBtn.Height := Height - 4;
>> EditBitBtn.Width := 32; {eg TMyEdit width is 100}
>> EditBitBtn.Align := alRight;
>> EditBitBtn.Parent := Self;
>> EditBitBtn.Visible := True;
>> Only thing you should check in ComponentState or ControlStyle (cannot
>> remember now), that maybe you should add to TMyEdit (in constructor)
>> that it allows child controls ...
>>
>> zeljko
>
> I solved the child thing with
>
> function TMyEdit.ChildClassAllowed(ChildClass: TClass): boolean;
> begin
>    inherited;
>
>    Result:=ChildClass=TBitBtn;
> end;
>
>
> But my problem is... If type more characters than the visible section of
> edit text and caret "lost" under the button.

It should look like this:

procedure TMyEdit.UpdateEditRect;
{$IFDEF LCLQt}
var
   R: TRect;
{$ENDIF}
begin
   if not HandleAllocated then
     exit;
   {$IFDEF LCLQt}
   if FButtonVisible then
     R := Rect(0, 0, FSB.Width, 0)
   else
     R := Rect(0, 0, 0, 0);
   TQtLineEdit(Handle).TextMargins := R;
   {$ENDIF}
end;

And it should be changed in FontChanged, Resize, button 
visible/true/false etc ... FSB.Width = YOurButton.Width

z.






More information about the Lazarus mailing list