秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  278 随笔 :: 0 文章 :: 308 评论 :: 20万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
2023年2月写的修复lazarus combobox的下拉列表在linux时没有高亮显示选中的item的问题,需然解决了显示问题,但下拉列表的颜色在银河麒麟是灰黑色,和应用的颜色明显不搭,想要win一样样式,如果要改变下拉背景颜色,可以按以下修改就可以,当然,如果不想用白色,可以改为想要的颜色。
打开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一样的颜色):

 

posted on   秋·风  阅读(235)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示