Download

Highlight Row (SListView)

I am trying to highlight a row in my table but it is displayed in a light grey:



SAssignNew(PlayerListWidget, SListView<TSharedPtr<FPlayerRow>>)
:
PlayerListWidget->SetItemSelection(PlayerRows[Idx], true, ESelectInfo::Type::OnMouseClick);
PlayerListWidget->SetItemHighlighted(PlayerRows[Idx], true);


SetItemHighlighted gives me the light grey color too. I am trying to get the yellow background color that appears when pressing with the mouse.
Any help is appreciated.

When you create widget for row, you can set style:



TSharedRef<ITableRow> SYourWidget::OnGenerateRowForList(TSharedPtr<YourItemClass> Item, const TSharedRef<STableViewBase>& OwnerTable)
{
  // not the best place for it, just for example ;)
  static auto CustomStyle = FCoreStyle::Get().GetWidgetStyle<FTableRowStyle>("TableView.Row");
  static auto const GreenHighlightBrush = FSlateColorBrush(FLinearColor(0.427, 0.701, 0.003));
  CustomStyle.SetActiveBrush(GreenHightlightBrush);  // selected but not hovered
  CustomStyle.SetActiveHoveredBrush(GreenHighlightBrush); // selected and hovered

  return SNew(STableRow< TSharedPtr<YourItemClass> >, OwnerTable)
             .Padding(2.0f)
             .Style(&CustomStyle)
              /* content */ ];
}


FTableRowStyle reference:

Thank you so much for the thoughtful reply @Emaer :slight_smile:

At the moment I am using the following two lines to achieve what I wanted to do:



PlayerListWidget->SetItemSelection(PlayerRows[Idx], true, ESelectInfo::Type::OnMouseClick);
FSlateApplication::Get().SetUserFocus(0, PlayerListWidget, EFocusCause::SetDirectly);


It works but what you provided as a nice dimension of control and possibility.