2023年2月写的修复lazarus combobox的下拉列表在linux时没有高亮显示选中的item的问题,需然解决了显示问题,但下拉列表的颜色在银河麒麟是灰黑色,和应用的颜色明显不搭,想要win一样样式,如果要改变下拉背景颜色,可以按以下修改就可以,当然,如果不想用白色,可以改为想要的颜色。
打开lazarus/lcl/include/customcombobox.inc
按以下修改后重新编译就可以。
缺点:下拉背景上和下各有1条黑线,暂时这样吧。
打开lazarus/lcl/include/customcombobox.inc
按以下修改后重新编译就可以。
缺点:下拉背景上和下各有1条黑线,暂时这样吧。
procedure TCustomComboBox.DrawItem(Index: Integer; ARect: TRect; State: TOwnerDrawState); begin //TControlCanvas(FCanvas).UpdateTextFlags; if Assigned(FOnDrawItem) then FOnDrawItem(Self, Index, ARect, State) else begin if not (odBackgroundPainted in State) then FCanvas.FillRect(ARect); InternalDrawItem(Self, FCanvas, ARect, Items[Index]) end; end;
改为:
procedure TCustomComboBox.DrawItem(Index: Integer; ARect: TRect; State: TOwnerDrawState); begin //TControlCanvas(FCanvas).UpdateTextFlags; //2022.05.28 LBZ
{$ifdef linux} if (FDroppedDown) then begin if (GetItemIndex=index) then //当为ItemIndex时高亮显示item begin FCanvas.Brush.Color := clHighlight; FCanvas.Font.Color := clHighlightText or clHighlight; State:=[odSelected]; end Else begin if not (odBackgroundPainted in State) then FCanvas.Brush.Color := clWhite;//下拉背景颜色 State:=[odFocused]; end; end; {$endif} //2022.05.28 LBZ if Assigned(FOnDrawItem) then FOnDrawItem(Self, Index, ARect, State) else begin if not (odBackgroundPainted in State) then FCanvas.FillRect(ARect); InternalDrawItem(Self, FCanvas, ARect, Items[Index]) end; end;
修改将下拉是用系统主题颜色的:
修改后,用自定的颜色(和win一样的颜色):