Adding a delay to a SToolTip widget

Hi,

I’m using the SToolTip widget. It’s nice and functional but it pops immediately when I hover an object.

What’s the easiest way to add a delay to this behavior ? Like, 1s hover opens it ?

Thanks a lot !

It looks like there is a Slate.ToolTipDelay console command but it doesn’t do anything in the game - it only applies to the editor.

Anyone ? :confused:

looks like you need to dig into the source doe and do some customization. I have came cross that a few times.

So basically I reimplemented tooltips entirely. Slate tooltips have two blocking issues :

  • Inability to handle delay and fading in the game viewport (they’re fine in editor)
  • Inability to be properly skinned : you can give them a style, sure, but a tooltip on a widget hierarchy will lose the style on the spaces between components of the widget. Think vertical row with a small item and a large item - the blank around the small item will have a system tooltip, not yours.

Don’t use tooltips in your game.

I found a way to display tooltip with a delay.

Create a class deriving from SToolTip

class KSGM_API SKTooltip : public SToolTip{ ... }

You need to use the Tick(), OnOpening(), OnClosed() and OnPaint()

The idea is to save the current time when OnOpening() is called and reset it in OnClosed()

	/**
	 * @brief Call-back executed when the tooltip is to be opened.
	 */
	virtual void OnOpening() override
	{
		OnOpeningTime = FSlateApplication::Get().GetCurrentTime();
	}

	/**
	* @brief Call-back executed when the tooltip is to be close.
	*/
	virtual void OnClosed() override
	{ 
		OnOpeningTime = 0.0f;
	}

In Tick() I calculate if the tooltip is ready to be displayed
The Delay member var contains the time in secs for the display delay.

void SKTooltip::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
	SToolTip::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);

	// Set the flag for visibility by calculating the remaining time 
	// before this tooltip can be displayed
	bDisplay = (OnOpeningTime > 0.0f) ? ((OnOpeningTime + Delay) - InCurrentTime) <= 0.0f : false;

}

In the first time I tough changing the widget’s visibility, but you cannot since the Tick function is called only for visible widget.
Then, I’ve used the OnPaint() call-back.

int32 SKTooltip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
	
	return (bDisplay) ? SToolTip::OnPaint(Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled) : LayerId;
}

I hope this will help.
D.