Recent

Author Topic: [Solved] How to calc width of OS scrollbar  (Read 3554 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
[Solved] How to calc width of OS scrollbar
« on: March 26, 2018, 07:11:47 pm »
E.g. in Listview OS scrollbar added if needed. How to calc it's width (of vert var) on all WS'es?
« Last Edit: March 26, 2018, 07:58:22 pm by Alextp »

Blaazen

  • Hero Member
  • *****
  • Posts: 3238
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to calc width of OS scrollbar
« Reply #1 on: March 26, 2018, 07:28:24 pm »
I did a test on Linux+Qt (I hope it will work for other WS'es too).
ListBox.Width gives 100 (default).
Empty ListBox.ClientWIdth gives 96 (2px border on both sides).
ListBox.ClientWidth with vertical scrollbar gives 80 (2*2px border + 16px scrollbar).

Alternatively, create a TScrollBar (Standart palette). Its default height is also 16.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How to calc width of OS scrollbar
« Reply #2 on: March 26, 2018, 07:49:15 pm »
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLIntf, LCLType;
  3. var
  4.   h, w: Integer;
  5. ...
  6.   h := GetSystemMetrics(SM_CYHSCROLL);
  7.   w := GetSystemMetrics(SM_CXVSCROLL);
Looks like a Windows call, but is in LCLIntf and, therefore, should be cross-platform.

Blaazen

  • Hero Member
  • *****
  • Posts: 3238
  • POKE 54296,15
    • Eye-Candy Controls
Re: [Solved] How to calc width of OS scrollbar
« Reply #3 on: March 26, 2018, 08:01:39 pm »
@ h := GetSystemMetrics(SM_CYHSCROLL);
  w := GetSystemMetrics(SM_CXVSCROLL);

I tried now, works well for Qt and GTk2. Also the trick with ClientWidth works with GTk2.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018