Recent

Author Topic: Items layout in TListView  (Read 12346 times)

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Items layout in TListView
« on: May 03, 2015, 08:08:30 pm »
Items are laid out in one row in TListView when ViewStyle:=vsIcon or vsSmallIcon
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var LV : TListView; I:integer;
begin
  LV:=TListView.Create(Self);
  LV.Parent:=Self;
  LV.Top:=10;
  LV.Left:=10;
  LV.ViewStyle:=vsSmallIcon;
  for I:=0 to 10 do
    LV.AddItem('Item',nil);
end;

end.

How to make them laying out in rows and columns?

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #1 on: May 03, 2015, 08:23:45 pm »
See IconOptions->Arrangement property

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #2 on: May 03, 2015, 08:26:09 pm »
THANKS!

Is there a way to align items by max item?
I mean, is there a way to set width of column equal to width of a widthest item, so all items are aligned vertically?
Now it looks messy.
« Last Edit: May 03, 2015, 11:27:22 pm by mm7 »

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #3 on: May 04, 2015, 08:40:32 am »
Have you played with IconOptions->AutoArrange and IconOptions->WrapText ?

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #4 on: May 04, 2015, 02:58:36 pm »
>Have you played with IconOptions->AutoArrange and IconOptions->WrapText ?

Yes, WrapText=true


zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #5 on: May 04, 2015, 04:10:53 pm »
So it's ok now ?

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #6 on: May 04, 2015, 06:03:34 pm »
No, it is not OK. :(
The picture was for the case with WrapText=true.

How "standard" Qt Open File dialog shows all neat and accurate?



zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #7 on: May 04, 2015, 06:09:00 pm »
Almost in same way. Open an issue about it and attach example project, so I'll take a look at it.

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #8 on: May 06, 2015, 12:20:50 am »
Hm. In small example project items are aligned well.
For some reason they are not in custom dialog that I am working on.
I'll try to figure it out....

Another things, while icons are centered in "columns", captions are adjusted to left.
Is it possible to control adjustments of captions or/and icons in vsIcon vsSmallIcon mode?


zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #9 on: May 06, 2015, 08:16:53 am »
By directly call Qt yes. If LCL TListItem have textalignment property then yes also (but might be unimplemented in qtlcl yet, so in that case you have to open an issue about it).

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #10 on: May 07, 2015, 02:02:33 pm »
Hi zeljko

I've managed to set adjustment of text inside ListItem with following custom procedure
Code: [Select]
procedure TForm2.SetQtItemTextAlignment(
  const ALV: TCustomListView;
  const AIndex: Integer;
  const Alignment: TAlignment );

const AlignmentToQtAlignmentMap: array[TAlignment] of QtAlignment =
(
{taLeftJustify } QtAlignLeft,
{taRightJustify} QtAlignRight,
{taCenter      } QtAlignCenter
);

var
  QtListWidget: TQtListWidget;
  TWI: QListWidgetItemH;
  AAlignment: QtAlignment;
begin
  //if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
  //  Exit;
  //if IsIconView(ALV) then
  begin
    QtListWidget := TQtListWidget(ALV.Handle);
    TWI := QtListWidget.getItem(AIndex);
    if TWI = nil
      then exit;
    AAlignment := AlignmentToQtAlignmentMap[Alignment];
    QListWidgetItem_setTextAlignment(TWI, AAlignment);
  end;
end;

However it aligns text only inside QListWidgetItem, relative to icon. The width of each QListWidgetItem still depends on width of text or icon, whichever is greater.

Problem is that items (icon and text together) are aligned in "columns" of ListView to the left.
Probably there should be another call to TQtListWidget to set their adjustment to center?
Could you please advise?

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Items layout in TListView
« Reply #11 on: May 11, 2015, 08:25:44 am »
TextElide mode should be set, so then you'll get width of text as you expected (elided of course).
Without code I cannot help you.

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: Items layout in TListView
« Reply #12 on: May 12, 2015, 02:12:26 pm »
Thanks zeljko

QListWidgetItem_setSizeHint helps to set a required size to items. (all should be set same).
« Last Edit: May 12, 2015, 07:03:36 pm by mm7 »

 

TinyPortal © 2005-2018