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一样的颜色):
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~