秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  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
lazarus Object Inspector和combobox的下拉列表在linux时没有高亮显示选中的item,在windows是有高亮显示的,按以下方法修改就可以,如果你有更有效的方法也请与我分享。
(lazarus版本:3.2.4 for gtk2,FPC版本:3.2.2,操作系统:银河麒麟 v10sp1)
windows版本是正常的:

 

 linux版本没显示选中的item,这是修正前:

修正后:

1、lazarus/lcl/include/customcombobox.inc

将109行的procedure TCustomComboBox.DrawItem添加红色代码:
复制代码
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;
      FCanvas.FillRect(ARect);
    end;
    FCanvas.Font.Color:= clMenuText;
  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;
  invalidate;
end;
复制代码

将1233行function TComboBoxStyleHelper.IsOwnerDrawn改为红色代码

复制代码
function TComboBoxStyleHelper.IsOwnerDrawn: Boolean;
const
  ArrIsOwnerDrawn: array[TComboBoxStyle] of Boolean = (
    True, // csDropDown //LBZ =false 改为自绘模式 true  2023.2.16
    True, // csSimple   //LBZ =false 改为自绘模式 true  2023.2.16
    True, // csDropDownList //LBZ =false 改为自绘模式 true 2023.2.16
    True,  // csOwnerDrawFixed
    True,  // csOwnerDrawVariable
    True,  // csOwnerDrawEditableFixed
    True   // csOwnerDrawEditableVariable
  );
begin
  Result := ArrIsOwnerDrawn[Self];
end;
复制代码

2、lazarus/components/ideintf/objectinspector.pp
将3517行的clWindowText改为clMenuText

复制代码
procedure TOICustomPropertyGrid.ValueComboBoxDrawItem(Control: TWinControl;
  Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
  CurRow: TOIPropertyGridRow;
  ItemValue: string;
  AState: TPropEditDrawState;
  FontColor: TColor;
begin
  if (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin
    CurRow:=Rows[FItemIndex];
    if (Index>=0) and (Index<ValueComboBox.Items.Count) then
      ItemValue:=ValueComboBox.Items[Index]
    else
      ItemValue:='';
    AState:=[];
    if odSelected in State then Include(AState,pedsSelected);
    if odFocused in State then Include(AState,pedsFocused);
    if odComboBoxEdit in State then
      Include(AState,pedsInEdit)
    else
      Include(AState,pedsInComboList);

    if not(odBackgroundPainted in State) then
      ValueComboBox.Canvas.FillRect(ARect);

    FontColor := ValueComboBox.Canvas.Font.Color;
    ValueComboBox.Canvas.Font.Assign(FDefaultValueFont);
    if odSelected in State then
      ValueComboBox.Canvas.Font.Color := FontColor
    else
      ValueComboBox.Canvas.Font.Color:= clMenuText;  //clWindowText LBZ 2023.2.16
    if CurRow.Editor.HasDefaultValue and (ItemValue = CurRow.Editor.GetDefaultValue) then
      ValueComboBox.Canvas.Font.Style := ValueComboBox.Canvas.Font.Style + [fsItalic];
    CurRow.Editor.ListDrawValue(ItemValue,Index,ValueComboBox.Canvas,ARect,AState);
  end;
end;
复制代码

 

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