Download

Change default tooltip widget OR idendify hovered widget at runtime ?

Hi,

Is there a way to change the default tooltip widget ?

I have hundreds of widget generated automatically in (sometimes nested) loops and i’d like them to have a custom widget.

I have tried to create a function that replaces the tooltip widget with a custom one:



void UYagMainWidget::AssignTooltipToWidget(UWidget* TargetWidget, FString TooltipMessage)
{
  if (!TargetWidget) return;

  if (!TooltipMessage.IsEmpty())
  {
    // createtool tip widget
    UYagToolTipWidget* ThisTooltipWidget = Cast<UYagToolTipWidget>(CreateWidget(this, TooltipUIClass));
    if (!ThisTooltipWidget) return;
    UCanvasPanelSlot* TooltipSlot = Cast<UCanvasPanelSlot>(ThisTooltipWidget->Slot);
    if (!TooltipSlot) return;

    ThisTooltipWidget->DisplayToolTip(TooltipMessage);

    TooltipSlot->SetAutoSize(true);

    // assign tooltip widget to current widget
    TargetWidget->SetToolTip(ThisTooltipWidget);
  }
    else
  {
    TargetWidget->SetToolTip(nullptr);
  }
}

It works well but with 100s of widgets it takes a lot of time because the tooltips are dynamics and i have to call it everytime i regenerate the widget list.
I can’t have my players to wait half a sec each time they need to see the list.

My custom widget is very simple, a border for the background + a text field with a custom font, so all this mechanics looks a bit like an overkill.
It would be so much simpler to just change the class of the default tooltip widget.

Anyone knows if that’s possible ?
I’m using the engine from the epic launcher, so modifying the engine code is not an option for me.

The problem here comes from the fact that this generic function has to know the TooltipText before hand.
So i guess another angle of attack would be to ask:
“Can a tooltip widget dynamically know the tooltip text of the hovered widget ?”
I couldn’t find a way to dynamically identify the hovered widget (the Interaction Widget has such a feature but it works only with UWidgetComponents, not with UWidgets, i tried).

Any suggestion/direction welcome !

Thanks
Cedric