[Lazarus] How to limit editor area of a TEdit

zeljko zeljko at holobit.net
Mon Feb 2 15:11:42 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.

Sure, I've shown you howto do it under pure LCL with Qt widgetset, now 
you should include qtwidgets in your code and handle textrect when 
clientsize of TEdit is changed (button is shown or hidden).You can do 
that by setting: TQtLineEdit(Handle).TextMargins := SomeRect;
Happy coding.

z.








More information about the Lazarus mailing list