Recent

Author Topic: listbox: cannot change itemheight  (Read 21875 times)

Blue1987

  • Full Member
  • ***
  • Posts: 165
listbox: cannot change itemheight
« on: June 17, 2011, 03:32:35 pm »
ehr, another problem about impagination!
I cannot change the itemheight in a listbox. I mean, it is as it was detetermined uniquely by the font size, and doesn't allow me to change the height keeping the font.size fixed!

am I doing sth wrong?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: listbox: cannot change itemheight
« Reply #1 on: June 17, 2011, 05:54:56 pm »
Rather confusingly, the Size property may not define what you regard as the Font's 'size'.
The font's Height specifies simply the dimensions of the characters.
The font Size has two meanings: positive values are the same as Height (but in non-metric units called points which are fractions of an inch [1/72]); negative values are point sizes that include the spacing or 'leading' above and below the displayed characters whih determine the line spacing.
If you have two dentical listboxes containing identical lines of text, and set one's font Size to 12 and the other's to -12 yoou'll see what I mean.

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #2 on: June 17, 2011, 07:11:57 pm »
Rather confusingly, the Size property may not define what you regard as the Font's 'size'.
The font's Height specifies simply the dimensions of the characters.
The font Size has two meanings: positive values are the same as Height (but in non-metric units called points which are fractions of an inch [1/72]); negative values are point sizes that include the spacing or 'leading' above and below the displayed characters whih determine the line spacing.
If you have two dentical listboxes containing identical lines of text, and set one's font Size to 12 and the other's to -12 yoou'll see what I mean.

ok, let us imagine i'll use only font-size:
- if I set "font.size = 10" it automatically set "font.height = -13";
- if I set "font.size = -10" it automatically set "font.height = 13";

ok. let us imagine now that I set I set font.size = -11 (and so automatically font.height=15), then I have the same graphical result as I set font.size = 9 (and so automatically font.height = -12); my question in this topic was about a property of listbox (not its font) which is listbox1.itemheight which is 15 in both cases, and cannot be changed, hence I do not understand its meaning!

bwt... I keep do not understanding how to keep "size" fixed (whatever number I chose) and meanwhile increase the spacing between lines (and that... here in listboxes, as well as in labels, as well as in memos)...

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: listbox: cannot change itemheight
« Reply #3 on: June 17, 2011, 10:25:30 pm »
Sorry, misunderstood your question.
The listbox control is a Lazarus wrapper around the native widgetset control on your platform.
Some platforms do not allow changing of the ItemHeight value after the listbox has been instantiated. So although it not declared as readonly, it behaves like that (for any given font size). This is certainly true on Windows. Others would have to tell you what is possible on Unixes and Mac OS X.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: listbox: cannot change itemheight
« Reply #4 on: June 17, 2011, 10:36:43 pm »
It works here (even if it gives some warning when I change ItemHeight).
Set:
ItemHeight=32
Style=lbOwnerDrawVariable
See screenshot.
Of course, you can also change Font.
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/

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #5 on: June 18, 2011, 12:38:29 am »
It works here (even if it gives some warning when I change ItemHeight).
Set:
ItemHeight=32
Style=lbOwnerDrawVariable
See screenshot.
Of course, you can also change Font.

ehr... if lbOwnerDrawVariable is on, I cannot change the color of the background (which is white by default) and the color of the font (black)...
is it all normal?


one more thing (I already asked in a similar topic... )... is it possible to do the same with multiline label? I mean, putting a spacing, of say 5pt, between the lines? I suppose it is possible using height and size ... but I cannot understand how to do it!


« Last Edit: June 18, 2011, 12:58:08 am by Blue1987 »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: listbox: cannot change itemheight
« Reply #6 on: June 18, 2011, 01:06:13 am »
When you set lbOwnerDrawVariable you will probably have to draw background yourself in OnDraw event.

About TLabel - probably no. We had TLabel topic here about it (http://www.lazarus.freepascal.org/index.php/topic,13399.msg70060.html#msg70060)
You can draw on Form directly in OnPaint event. Or make your own component for it.
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/

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #7 on: June 18, 2011, 01:14:06 am »
You can draw on Form directly in OnPaint event. Or make your own component for it.

it doensn't look so "yeah" :)

[and the second choice is something I think I cannot do, since I really am a beginner...]


btw... thank you for your help!

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #8 on: June 18, 2011, 01:16:25 am »
what if I write the text directly on label canvas??

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: listbox: cannot change itemheight
« Reply #9 on: June 18, 2011, 01:34:45 am »
Yes, you can do it (more info is in the link I posted before). But it works little differently on linux and windows.
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/

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #10 on: June 18, 2011, 01:51:46 am »
Yes, you can do it (more info is in the link I posted before). But it works little differently on linux and windows.

now new problem [not considering that also with antialias the text doesn't seem so good :) ]
is it possible to write text on a canvas with right allignment ? :)


aaaaah, getting mad! (hope in the next release of lazarus, labels - and memos - will have the spacing property by default!!)

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #11 on: June 18, 2011, 03:20:08 am »
Yes, you can do it (more info is in the link I posted before). But it works little differently on linux and windows.

now new problem [not considering that also with antialias the text doesn't seem so good :) ]
is it possible to write text on a canvas with right allignment ? :)


aaaaah, getting mad! (hope in the next release of lazarus, labels - and memos - will have the spacing property by default!!)


I feel really stupid... I spent three hours to find this solution (that at least works!!!)

Code: [Select]
procedure TForm1.Sfondo19Paint(Sender: TObject);
begin

label682.Canvas.Font.Name:=label682.font.name;
label682.Canvas.Font.size:=label682.font.size;
label682.Canvas.Font.color:=label682.font.color;
label682.canvas.font.Quality:=label682.font.Quality; {antialiased}
label682.Caption:='';

label682.Canvas.TextOut(label682.Width-label682.Canvas.TextWidth('Pr)'),0,'Pr)');

for i:=1 to 10 do begin
temp_str:='At';
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].Y > 6 then temp_str:='Co';
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].Y > 11 then temp_str:='Cc';
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].Y > 20 then temp_str:='Cd';
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].Y > 24 then temp_str:='Df';
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].X < 6 then temp_str:=temp_str + 'S' else
if tattica[squadra[puntatore_squadra].tattica].ruolo[i].X < 19 then temp_str:=temp_str + 'C' else
temp_str:=temp_str + 'D';
label682.Canvas.TextOut(label682.Width-label682.Canvas.TextWidth(temp_str+')'),i*20,temp_str+')');
end;
end;

can I also make the text "smooth"? (since fqDraft doesn't work well if the label is transparent!!!)
« Last Edit: June 18, 2011, 03:52:08 am by Blue1987 »

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #12 on: June 19, 2011, 05:36:15 am »
make your own component for it

btw... is there someone who could explain me how to do it? or maybe doing it for me :)    O:-) O:-) O:-)
[I really am a beginner, and really do not know how to start!!! otherwise of course I would have done it by my-self!!]

I mean.. it would be really useful having a multiline label which allows to set the height of lines, with a vertical_in-line_align_property of text...
[I say... at least for the tlabel, even though I think it is something really useful for graphics design, and it would be also useful for tmemo... and maybe a better implementation of tlistbox - that is... sth which let me change colors of listbox items]

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: listbox: cannot change itemheight
« Reply #13 on: June 19, 2011, 01:25:04 pm »
To see how the LCL does right-aligned painting of TLabel, look at the Paint method of TCustomLabel.
The DoMeasureTextPosition() method calculates the correct value for TextLeft in the TextRect() call which paints the label text on the canvas, depending on whether the label's Alignment is taCenter, taLeftJustify, or taRightJustify.
Your own custom component could copy this code, and adjust the spacing of the lines of text according to your wishes.

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: listbox: cannot change itemheight
« Reply #14 on: June 20, 2011, 04:44:42 pm »
To see how the LCL does right-aligned painting of TLabel, look at the Paint method of TCustomLabel.
The DoMeasureTextPosition() method calculates the correct value for TextLeft in the TextRect() call which paints the label text on the canvas, depending on whether the label's Alignment is taCenter, taLeftJustify, or taRightJustify.
Your own custom component could copy this code, and adjust the spacing of the lines of text according to your wishes.

thank you... since I've started hanging around this forum my knowledge of Lazarus, and programming in general, has improved a lot!
sooner or later, I hope I'll stop being a beginner :)

 

TinyPortal © 2005-2018