lazarus在银河麒麟国产操作系统linux下,使用TListView 使用TListView vsIcon 样式,文本长了会是这样效果
尝试设置 OwnerDraw 属性为 True
自己定义方法 DrawItem 不起效果
也尝试修改 TCustomListView 源代码也不起效果,
搞了半天,后发现坑了,没仔细看帮助
When set to True, the OnDrawItem event handler is signalled to draw list items when the control is using the Report view style (ViewStyle = vsReport). The handler is signalled (when assigned) from the DrawItem method, and occurs when the CN_DRAWITEM control notification message is handled for the control. It should handle all aspects of drawing the list item to the control Canvas. If OnDrawItem has not been assigned, a basic default drawing routine is used.
只有ViewStyle = vsReport 也可调用 DrawItem
vsIcon 是调系统gtk自己画的
本质还是系统问题不是 lazarus 问题
后面不折腾了,自己程序代码完善一下
function MinimizeText(const Text: string; Canvas: TCanvas; MaxWidth: Integer): string;
var
I: Integer;
begin
Result := Text;
I := 1;
while (I <= Length(Text)) and (Canvas.TextWidth(Result) > MaxWidth) do
begin
Inc(I);
Result := Copy(Text, 1, Max(0, Length(Text) - I)) + '...';
end;
end;
长的文本加...
vLI := ListView1.Items.Add;
vLI .Caption := MinimizeText(AQry.FieldByName('sfilename').AsString, ListView1.Canvas ,100);
vLI .SubItems.Add(AQry.FieldByName('iid').AsString);
vLI .SubItems.Add(AQry.FieldByName('sfilename').AsString);