Recent

Author Topic: Combobox OwnerDraw appearance is different between GTK2 and Qt  (Read 7338 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Combobox OwnerDraw appearance is different between GTK2 and Qt
« on: November 24, 2014, 03:00:55 pm »
When using an ownerdraw combobox with GTK2 (Linux Mint 17 and i7 PC with Laz 1.2.6 and FPC 2.6.4) they appear very differently.

The GTK2 version works as I expect it to, but the Qt version does not expand and draw the items correctly, and does not show the text.

Uncommenting the ItemHeight := 25 line provides a better output but no text.

The attachments show the differences.
Code: [Select]
procedure TfrmMainScreen.cbMinSpeedDrawItem(Control: TWinControl;
  Index: integer; ARect: TRect; State: TOwnerDrawState);
begin
  with cbMinSpeed do
  begin
    //Next line improves Qt combobox height appearance
    //ItemHeight := 25;

   //SpeedColour is an array of TColor which contains 20 colours
    Canvas.Brush.Color := SpeedColour[Index];
    Canvas.FillRect(ARect);
    Canvas.TextOut(10, 6, '>=' + IntToStr((Index) * 5));
end;

There seem to be two differences:

1) The size of each item, with Autosize working in GTK2 but not in Qt.
2) The lack of text in Qt.

Is this known and expected behaviour?

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #1 on: November 24, 2014, 03:19:53 pm »
Quote
2) The lack of text in Qt.
Why should text be there, when you use OwnerDraw, you are on your own.

BTW, do you use OwnerDrawFixed or ...Variable?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #2 on: November 24, 2014, 09:34:09 pm »
The application is plotting a GPS track, with different colours for different speeds. The intent is to select a speed below which the plot is nor shown. It works fine in both GTK2 and Qt if I just populate the combobox with text and have a standard colour background.

I decided to make the combo box background colour match the plotted colour and used the OwnerDraw event to do this. GTK2 works perfectly, so I assume it is a Qt LCL problem. (I do remember reading a 'What won't ever be fixed in Qt' post. I will check that out.)

I am using OwnerDrawFixed.

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #3 on: November 24, 2014, 09:52:51 pm »
I have fixed it in Qt by changing a line in the code so that it indexes down the combo
box popup.

It seems that when using OwnerDraw that GTK draws relative to each item focus rectangle, and that Qt draws relative to the whole combobox popup rectangle .

Code: [Select]
    Canvas.TextOut(10, 6 + 25*Index, '>=' + IntToStr((Index) * 5));

Code: [Select]
procedure TfrmMainScreen.cbMinSpeedDrawItem(Control: TWinControl;
  Index: integer; ARect: TRect; State: TOwnerDrawState);
begin
  with cbMinSpeed do
  begin
    //Next line improves Qt combobox height appearance
    ItemHeight := 25;

   //SpeedColour is an array of TColor which contains 20 colours
    Canvas.Brush.Color := SpeedColour[Index];
    Canvas.FillRect(ARect);
    Canvas.TextOut(10, 6 + 25*Index, '>=' + IntToStr((Index) * 5));
end;

Is this something that should be changed in LCL?

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #4 on: November 25, 2014, 11:00:49 am »
I have found that my code does not work properly with GTK2, because it the combo box is now empty when it opens. I am now exploring all of the events to see which ones to use.

I'll post the solution here when I have it.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #5 on: November 25, 2014, 07:32:57 pm »
Why should text be there, when you use OwnerDraw, you are on your own.
OwnerDraw means the developer can draw anything - including text. There is NO rule that says text may not be used.

What he is experiencing is exactly what I found back in 2006. Not all LCL-xxx widgetsets are created equal. LCL also doesn't play nice with custom drawing, or limits it. Hence fpGUI Toolkit was born.

Back to the problem at hand. It seems the LCL-QT doesn't allow adjusting the height of the dropdown windows or elements within it - or simply that functionality hasn't implement in LCL-Qt yet.

G.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #6 on: November 25, 2014, 07:35:04 pm »
Is this something that should be changed in LCL?
I would consider it a bug, and yes LCL-QT should be fixed.

G.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #7 on: November 25, 2014, 09:02:29 pm »
Quote
OwnerDraw means the developer can draw anything - including text. There is NO rule that says text may not be used.
I would expect that in OwnerDraw style (and assigned OnDrawItem) there will be empty area where developer can draw anything; colourful background + some custom text in this case.

I did a test, style OwnerDrawFixed and OwnerDrawVariable:

Wine Laz. 1.2.6:
OnDrawItem assigned: no text
OnDrawItem not assigned: text is there

Qt Laz. 1.3:
OnDrawItem assigned: no text
OnDrawItem not assigned: text is there

GTk2 Laz. 1.3:
OnDrawItem assigned: no text
OnDrawItem not assigned: no text

So the only bug is incosistency in GTk2, it doesn't display text when OnDrawItem is not assigned while other widgetsets do.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #8 on: November 25, 2014, 10:05:25 pm »
This is my current version of the code. The differences between GTK and Qt are shown in the {$IfDef ...} statements

GTK2 does not populate the combo box when it is opened, and the combobox has to be scrolled to populate. Qt does it as expected.

The Item height in he Object Inspector is 13, but must be 25 or similar in Qt. (That looks like a multiple of 2.)

SpeedColour is an array with 20 TColor values in it.


Code: [Select]
procedure TfrmMainScreen.cbMinSpeedDrawItem(Control: TWinControl;
  Index: integer; ARect: TRect; State: TOwnerDrawState);
var
  VPos: integer;
  Cnv: TCanvas;
begin
  if not (Control is TComboBox) then
    Exit;
  Cnv := TComboBox(Control).Canvas;
  Cnv.Brush.Color := SpeedColour[Index];
  Cnv.FillRect(ARect);

  //Itemheight := 13 in Object Inspector.
  {$IfDef Qt}
  cbMinSpeed.ItemHeight := 25;
  VPos := 6 + 25 * Index;
  {$EndIf}

  {$IfDef GTK2}
  VPos := 6;
  {$EndIf}

  if (Togbox1.Caption = Rsauto) then
    Cnv.TextOut(10, VPos, '>=' + IntToStr((Index) * GetSpdScale))
  else
    Cnv.TextOut(10, VPos, '>=' + IntToStr((Index) * 5));

end;
« Last Edit: November 26, 2014, 12:08:50 pm by Windsurfer »

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Combobox OwnerDraw appearance is different between GTK2 and Qt
« Reply #9 on: December 08, 2014, 06:03:16 pm »
I have noticed the ComboBox OnGetItems event, and tried to use it to populate the list when it pops up.

The help says: 'Handler invoked when widgetset items list can be populated
Some widgetsets like gtk call this just before the list drops down, while others do it on handle creation. This event allows one to handle both cases with one event.'

However, the following code does not populate the popup list. I still have to scroll the list manually for the poppedup list to be populated.

Code: [Select]
procedure TfrmMainScreen.cbMinSpeedGetItems(Sender: TObject);
var
  I: integer;
begin
  For I := 0 to 19 do cbMinSpeed.Items[I] := IntToStr((I));
end;

Have I misunderstood how to use it?

 

TinyPortal © 2005-2018