Recent

Author Topic: How do I enable switching between tabs via <ctrl>-<tab> and <ctrl>-<shift>-<tab>  (Read 6708 times)

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Theorically it's just for that but IIRC it's one of those (so many!) things that depend on the widgetset, the support in the WM and the phase of the moon. One can but try it in one's program and be aware of the possible workarounds in case it doesn't work.

Indeed, I forgot the phase of the moon.
 %)

I am using the solution from taazz:

go simple use actions.
1) add an actionlist in your form
2) add two new actions
3) named appropriatly eg actTabforward and actTabBack.
4) write on the onexecute hcode like
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ActTabForwardExecute(Sender :TObject);
  2. begin
  3.   if PageControl1.TabIndex = 0 then PageControl1.TabIndex = PageControl1.PageCount -1
  4.   else PageControl1.TabIndex := PageControl1.TabIndex - 1;
  5. end;
  6.  
  7. procedure TForm1.ActTabBackExecute(Sender :TObject);
  8. begin
  9.   if PageControl1.TabIndex = PageControl1.PageCount -1 then PageControl1.TabIndex := 0
  10.   else PageControl1.TabIndex := PageControl1.TabIndex+1;
  11. end;
  12.  
5) make sure the actions have the appropariate shortcuts ctrl+tab and shift+ctrl+tab.

done.


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Better than manipulating TabIndex, use SelectNextPage(), as zoltanleo said. Way cleaner! ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Yukiko

  • Jr. Member
  • **
  • Posts: 55
In my case, Taazz's solution was better because I have a hidden page that I use to display various debugging info. I unhide it for testing and rehide it for the release. I just skip to the first page when the last normally visible page is active. However, in normal cases, I can see where your solution, zoltanleo, would be more optimal.

OLLI_S

  • Full Member
  • ***
  • Posts: 119
I also have a "hidden" tab for debug information.
But I allow the user to make it visible (so when any problem occurs then I can tell the user to send me the the debug information).
So I check if the tab is shown or not and then set the TabIndex to the correct tab.
« Last Edit: February 28, 2019, 10:31:08 am by OLLI_S »

zoltanleo

  • Sr. Member
  • ****
  • Posts: 486
@Yukiko
@OLLI_S

There is an overloaded method SelectNextPage(GoForward: Boolean; CheckTabVisible: Boolean) that call inside FindNextPage method
Code: Pascal  [Select][+][-]
  1. procedure TPageControl.SelectNextPage(GoForward: Boolean;
  2.   CheckTabVisible: Boolean);
  3. var
  4.   NextPage: TTabSheet;
  5. begin
  6.   NextPage:=FindNextPage(ActivePage,GoForward,CheckTabVisible);
  7.   if NextPage<>nil then ActivePage:=NextPage;
  8. end;

2nd parameter CheckTabVisible: Boolean takes into account the invisible tabs. For more see here: https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/tpagecontrol.selectnextpage.html
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

OLLI_S

  • Full Member
  • ***
  • Posts: 119
There is an overloaded method SelectNextPage(GoForward: Boolean; CheckTabVisible: Boolean) that call inside FindNextPage method
2nd parameter CheckTabVisible: Boolean takes into account the invisible tabs. For more see here: https://lazarus-ccr.sourceforge.io/docs/lcl/comctrls/tpagecontrol.selectnextpage.html

Hello zoltanleo,

thank you very much for your posting!

Your solution is just one line (here I write both lines, for switching to the next and previous page):
Code: Pascal  [Select][+][-]
  1. pgePages.SelectNextPage(True, True);  // Go to next visible page
  2. pgePages.SelectNextPage(False, True); // Go to previous visible page

My current solution was 5 lines for each  direction, now I just have one line.
So thank you!

OLLI
« Last Edit: March 01, 2019, 12:06:12 pm by OLLI_S »

 

TinyPortal © 2005-2018