Combobox OwnerDraw appearance is different between GTK2 and Qt lazarus / 31-LCL ---------------------------------------------------------------------- Windsurfer · 2014-11-24 14:00 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 · 2014-11-24 14:19 Quote2) 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? ---------------------------------------------------------------------- Windsurfer · 2014-11-24 20:34 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 · 2014-11-24 20:52 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 · 2014-11-25 10:00 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 · 2014-11-25 18:32 Quote from: Blaazen on November 24, 2014, 03:19:53 pmWhy 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. ---------------------------------------------------------------------- Graeme · 2014-11-25 18:35 Quote from: Windsurfer on November 24, 2014, 09:52:51 pmIs this something that should be changed in LCL? I would consider it a bug, and yes LCL-QT should be fixed. G. ---------------------------------------------------------------------- Blaazen · 2014-11-25 20:02 QuoteOwnerDraw 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. ---------------------------------------------------------------------- Windsurfer · 2014-11-25 21:05 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; ---------------------------------------------------------------------- Windsurfer · 2014-12-08 17:03 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?