Lazarus

Programming => General => Topic started by: elioenaishalom on August 11, 2019, 10:00:53 pm

Title: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: elioenaishalom on August 11, 2019, 10:00:53 pm
My ListView was OK, but when I added pictures to column 2, the caption column, with or without checkbox, showed erratic behavior.
(see picture added)
Is that the way it should be?
Any alignment gives the same result.

Can anyone clarify? Thank you in advance.  :D

Lazarus 2.0.2 32bit Ideapad 15IKB Notebook, I7-7500U Processor, 16.0 GB RAM - Windows 10 Home 1809 OS
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: jamie on August 12, 2019, 12:44:37 am
I see the image but I don't see what the erratic behavior is?

Are you referring to the selection in blue? if so that is normal for selecting the Row I guess.

if this is something else I am not seeing please advise...

btw.

 TImageList by default assumes all images are of the same size so if you are using this as an ICON
view then I would assume each image you added was resized to fix the size?

 Also there is a recent release of Lazarus, 2.0.4. I can't say that it will fix your issue but I Know it will solve some leaks that existed in 2.0.2


 I wanted to add that you can I believe do OwnerDraw mode, this means you can custom draw the surfaces.

Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: elioenaishalom on August 12, 2019, 02:45:57 am
Mr. Jamie,

Thank you for your interest.

Line Selection: The line is only partially selected, reserving an area to the right of the checkbox.

Style: ViewStyle is vsReport;
All figures are pre-existing with the same size (128x72 pixels) and are added to TImagelist at run-time during the first Form.activate.

I have attached version without TImageList and with TImageList. Please verify.

Column resize: It seems to me that when using pictures, an area is allocated to the right of the checkbox equivalent to the width of the picture even without using a picture in the caption column.

OwnerDraw: I'm sorry but I have no experience and don't master OwnerDraw mode; perhaps I will soon dive into this ocean.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: wp on August 12, 2019, 09:29:19 am
Please provide a compilable example project showing the issue.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: elioenaishalom on August 12, 2019, 05:33:36 pm
Mr. wp,

attached a project for your verification.
I provided four same-sized bitmaps (128x72 pixels) to populate Listview.
I hope it fits your demand.

Thank you.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: elioenaishalom on August 13, 2019, 11:39:27 am
 :o
OK, so be it ...
the caption column allocates the width of the picture plus 5 pixels, cf. the attached tests with 3 different picture widths.
Excuse me but any  ;) like myself concludes the component is not correct as the user is captive of this abnormal behavior.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: marcov on August 13, 2019, 03:29:57 pm
Locking threads is only for special cases, not a matter of routine.

It is considered not proper behaviour not allowing other people the ability to comment.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: wp on August 13, 2019, 03:54:26 pm
I don't know if this is a bug or a feature. When an ImageList is attached to a ListView, the captions in the first column move to the right to give way to the images. Drawing images only when needed would result in a ragged left side of the 1st column which looks strange. It should also be noted that the Listview is painted essentially by the widgetset, i.e. by routines of the operating system. Therefore, the LCL cannot change this behavior.

You could try to remove the ImageList from Listview and owner-draw the column with the images in the OnCustomDrawSubItem event:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  2.   Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  3.   var DefaultDraw: Boolean);
  4. var
  5.   R: TRect;
  6. begin
  7.   R := Item.DisplayRectSubItem(1, drBounds);  // 1 = index of image column
  8.   ImageList1.Draw(Sender.Canvas, R.Left, R.Top, Index);
  9. end;
When doing this I faced the problem that I did not find a way how to increase the row heights of the ListView to fit the image heights. Maybe it is easy, maybe it requires system calls - I don't know...

But normally I would not use a TListView for this programming task at all. I'd use a plain old StringGrid instead which can be configured to look almost like a TListView and allows much more control. I am attaching a modified version of your demo based on a stringGrid.
Title: Re: Column size in TListview (vsReport with TImagelist linked) apparently random.
Post by: elioenaishalom on August 13, 2019, 10:50:29 pm
OK thank you for the attention
TinyPortal © 2005-2018