Lazarus

Programming => General => Topic started by: seany on January 31, 2023, 04:21:37 am

Title: CheckComboBox Item Width
Post by: seany on January 31, 2023, 04:21:37 am
When you click on a CheckComboBox, it creates a dropdown list.
The Dropdown list has the same width as the CheckCombobox itself, even if there are items where the textwidth is much higher.

How can we ensure that the dropdown list automatically expand to show the full text width of items? Thank you.

Title: Re: CheckComboBox Item Width
Post by: KodeZwerg on January 31, 2023, 04:29:31 am
Since you give no clue about your target OS nor your FPC/Lazarus versions, here (https://blog.dummzeuch.de/2019/06/22/setting-the-drop-down-width-of-a-combobox-in-delphi/) is my answer for Windows OS written in Delphi, but logic is same.
Title: Re: CheckComboBox Item Width
Post by: seany on January 31, 2023, 04:46:37 am
My bad

Lazarus 2.2.4
FPC : 3.2.2

Linux x86_64 QT5
Title: Re: CheckComboBox Item Width
Post by: Joanna on March 23, 2023, 10:52:23 pm
You will need to constrain the width of the checkcombobox to fit the widest string. I’m usually in irc. If you wish to discuss further.
Title: Re: CheckComboBox Item Width
Post by: paweld on March 24, 2023, 07:50:52 am
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i, w, max: Integer;
  4. begin
  5.   max := ComboBox1.Width;
  6.   for i := 0 to ComboBox1.Items.Count - 1 do
  7.   begin
  8.     w := ComboBox1.Canvas.TextWidth(ComboBox1.Items[i]);
  9.     if w > max then
  10.       max := w + 10;
  11.   end;
  12.   ComboBox1.ItemWidth := max;
  13. end;
Title: Re: CheckComboBox Item Width
Post by: paweld on March 24, 2023, 10:12:19 am
and for CheckComboBox: 
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLIntf, LCLType;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. var
  6.   i, w, max: Integer;
  7. begin
  8.   max := CheckComboBox1.Width;
  9.   for i := 0 to CheckComboBox1.Items.Count - 1 do
  10.   begin
  11.     w := CheckComboBox1.Canvas.TextWidth(CheckComboBox1.Items[i]);
  12.     if w > max then
  13.       max := w + 10 + GetSystemMetrics(SM_CXMENUCHECK) {check width};
  14.   end;
  15.   CheckComboBox1.ItemWidth := max;
  16. end;    
  17.  
Title: Re: CheckComboBox Item Width
Post by: Joanna on March 24, 2023, 12:26:25 pm
Hi paweld  :D
Today  I made an interesting discovery about checkcombobox...

if you add strings to the checkcombobox items it will compile just fine but cause an amazing crash in the ondrawitem event because the Items.objects[index] part which represents the checkboxes? apparently nil.

The only way I know of to add things to checkcombobox is to use the additem procedure. Which adds things one by one. I’ll definitely need to improve upon that.

Another thing I’m unsure about is how checkboxes are enabled and disabled and how to control color of checkboxes
Title: Re: CheckComboBox Item Width
Post by: jamie on March 24, 2023, 10:42:29 pm
Yes, we must have PINK check boxes.
 :o
Title: Re: CheckComboBox Item Width
Post by: Joanna on March 25, 2023, 03:42:08 pm
Yes, we must have PINK check boxes.
 :o
Do you know how to make them? I was told that the system controls the drawing of them. Maybe a custom drawn checkcombobox is needed ...
TinyPortal © 2005-2018