Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-02

How to limit editor area of a TEdit

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

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?

Gabor

Reply by email

zeljko
to Gabor Boros
Gabor Boros wrote 5 lines
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

Reply by email

zeljko
Gabor Boros wrote 35 lines
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.

Reply by email

zeljko
Gabor Boros wrote 35 lines
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.

Reply by email

Gabor Boros
to zeljko

2015.02.02. 15:13 keltez?ssel, zeljko ?rta:

Show quoted text 24 lines
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.

Works like a charm! Thank you very much Zeljko!

Gabor

Reply by email

Gabor Boros
to zeljko: Sure, I've shown you howto do it under pure LCL with Qt widgetset, now you should include…

2015.02.02. 15:11 keltez?ssel, zeljko ?rta:

Show quoted text 7 lines
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.

I am happy and coding... :-)

Thank You again!

Gabor

Reply by email