Lazarus
Programming => Widgetset => QT => Topic started by: mm7 on May 03, 2015, 08:08:30 pm
-
Items are laid out in one row in TListView when ViewStyle:=vsIcon or vsSmallIcon
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?
-
See IconOptions->Arrangement property
-
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.
-
Have you played with IconOptions->AutoArrange and IconOptions->WrapText ?
-
>Have you played with IconOptions->AutoArrange and IconOptions->WrapText ?
Yes, WrapText=true
-
So it's ok now ?
-
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?
-
Almost in same way. Open an issue about it and attach example project, so I'll take a look at it.
-
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?
-
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).
-
Hi zeljko
I've managed to set adjustment of text inside ListItem with following custom procedure
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?
-
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.
-
Thanks zeljko
QListWidgetItem_setSizeHint helps to set a required size to items. (all should be set same).