Recent

Author Topic: How to display same LCL widget in different TabSheets  (Read 7103 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
How to display same LCL widget in different TabSheets
« on: June 18, 2021, 04:14:26 pm »
I have an app with different TabSheet tabs. To speed up he work flow, I want to display the _same_ panel in 2 different tabs.

So I have now a panel in one TabSheet and want to display the same panel now also in another TabSheet .

Is this possible?

Lazarus 2.3.0 r65271 FPC 3.2.2 x86_64-win64-win32/win64

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to display same LCL widget in different TabSheets
« Reply #1 on: June 18, 2021, 04:30:15 pm »
Hi!

Use the onChange event of the PageControl to change the parent of the panel to the AktivePage:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PageControl1Change(Sender: TObject);
  2. begin
  3.   Panel1.Parent :=  PageControl1.ActivePage;
  4.   Application.ProcessMessages;
  5. end;            


Winni
« Last Edit: June 18, 2021, 04:39:30 pm by winni »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: How to display same LCL widget in different TabSheets
« Reply #2 on: June 18, 2021, 04:58:36 pm »
I don't know what exactly you want to achieve. But basically the tabbed control which displays the same page content on all tabs is a TTabControl, unlike a TPageControl in which every tab can be different.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: How to display same LCL widget in different TabSheets
« Reply #3 on: June 18, 2021, 05:05:08 pm »
Don't know why OP needs it. If what he wants is showing same components on different tabsheets, I ever done it.

Just set the components' parent to the active tabsheet and put the code in the page control's OnChange event.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to display same LCL widget in different TabSheets
« Reply #4 on: June 18, 2021, 05:58:40 pm »
Don't know why OP needs it. If what he wants is showing same components on different tabsheets, I ever done it.

Just set the components' parent to the active tabsheet and put the code in the page control's OnChange event.

Hi

I showed the technical solution above.

The reasons for this strange design might be two:

* He wants to show important state information on all different pages

OR

* He wants to draw infos depending on the Tabsheet but he does not want to waste a panel for each page.


Anyway: The easier solution would be to shrink the pagecontrol and put the panel outside the pagecontrol on the form.

But who knows the strange desires if he does not want  to tell us ....

Winni

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: How to display same LCL widget in different TabSheets
« Reply #5 on: June 18, 2021, 06:10:24 pm »
I didn't read your previous post. I posted my answer when I was busy watching the TV.  :P

Yes, the easiest is to put that 'thing' outside the page control.

I often doing something weird. Not satisfied with TFrame and not willing to use MDI, I wrote my custom form and put it on TabSheet on runtime. So I need to put some buttons for managing the 'forms', which they should be always shown on all tabs. It worked, although I don't think that is the best approach.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to display same LCL widget in different TabSheets
« Reply #6 on: June 18, 2021, 06:36:04 pm »
I didn't read your previous post. I posted my answer when I was busy watching the TV.  :P


Hi!

Reduce the size of the brower with theTV to a quarter.
Put it in the topright corner.
Tell it to stay on top.

That's the way I do it,

Winni

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: How to display same LCL widget in different TabSheets
« Reply #7 on: June 19, 2021, 02:35:50 am »
I don't know what exactly you want to achieve.

I have a quite complex UI with many tabs. To spread the same info across different UI positions, i want to duplicate e.g. a lineEdit.

Attached is an example where i have a LineEdit it Tab 2. The LineEdit that it is Tab 1 should be an exact copy of the one in Tab 2 - same size, enable state, value, hint...
it is hereby important that the users doesn't need to change the tab. So the LineEdit in Tab 1 if changed for some reason, he sees it immediately in Tab 2.

At the moment I do it like in the attached example but I thought there is a more simpler solution.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: How to display same LCL widget in different TabSheets
« Reply #8 on: June 19, 2021, 02:41:08 am »
* He wants to draw infos depending on the Tabsheet but he does not want to waste a panel for each page.

No, I have several tabs which all look different. When the user is in Tab 7  he should see a change happening in Tab 3. But when he is in Tab 5, he should not see the info at all. Therefore I cannot place the LineEdit outside the PageControl. See the example in my last post.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: How to display same LCL widget in different TabSheets
« Reply #9 on: June 19, 2021, 02:53:20 am »
Use the onChange event of the PageControl to change the parent of the panel to the AktivePage:

That would be a nice idea, but unfortunately, the widgets are at different locations in the tabs. With your solution, the panel would appear at the same position in every tab.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to display same LCL widget in different TabSheets
« Reply #10 on: June 19, 2021, 03:07:40 am »
Use the onChange event of the PageControl to change the parent of the panel to the AktivePage:

That would be a nice idea, but unfortunately, the widgets are at different locations in the tabs. With your solution, the panel would appear at the same position in every tab.

You can easily change the widgets position at the same time as you change its parent. But from a user perspective, having an important widget appear in the same position on each tabpage is a good idea. The user would feel quite seasick if the widget appears to  jump around when they change a tab. 

Davo

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018