Setting position of widget to mouse position

Maybe because your “-120” doesn’t fit all resolutions. What is this number based of? Could you maybe calculate it so that it changed from resolution to resolution?

1 Like

I am creating a custom tooltip via a widget.
I have had mixed results getting the widget to appear at the desired location.
It works great in the window the editor provides for debugging.
But if I play full screen, change the resolution or maximize the window the widget appears in the wrong spot.

The -120 moves the tooltip to the left of the mouse.
It is based off of the size of the widget.
Usually the widget appears too far to the right when I change the resolution or maximize the window.
I’m pretty sure I would need to call some type of “ScreenRatio” type function to get the correct position.
I’m just not sure how it would be done.

It’s always 120 to the left, so if you have 800 width, it seems more as than you have 1920 width. So to get the differents you would need to choose a default resolution and get the factor the rest of the resolutions.

Ehm, a bit math, let the me a sec…

Let’s say 1920x1080 is your default resolution. So in this resolution, you have your -120 (i guess you need to adjust this number first because you had a low resolution as “default”). So we need a lower number for lower resolution i guess. Otherwise the widget will be placed way to far the left in lower resolutions. So to get that factor you need to devide the actual screen size through the default size.

So for our example it would be:

800 / 1920 = ca 0.417

0.417 * 120 = ca 50.00

So this would be the new value for the minus Node.

Would you try this and tell me if it’s working or if it needs some more tweaks?

It could be that you need your HUD from the Player Controller and the Viewport Size from
this. If you can’t find it, i will have a look at my UE4 to find it for you.

Thanks for your help.
But the problem happens even if I remove the minus node all together and just use the raw mouse position.

I hit play it starts in a 1920 x 1080 window.
I mouse over the item and get this tooltip:


Then I maximize the same window and mouse over and get this:

When I was creating my game from scratch I would make a call like this:

Vector2D My_Map::GetMapCoordinates(float x, float y)
	float screenRatioX, screenRatioY;
	bool result = _tile.getGraphics()->GetScreenRatio(screenRatioX, screenRatioY);
	float screenX = x * screenRatioX;
	float screenY = y * screenRatioY;

	int column = (int)(screenX / _tile.TextureWidth);
	int row = (int)(screenY / _tile.TextureHeight);

	return Vector2D(column, row);

	bool Graphics::GetScreenRatio(float &screenRatioX, float &screenRatioY)
		bool output = false;

		if (getFullscreen() == false) // if windowed
			// calculate screen ratios incase window was resized
			RECT clientRect;
			GetClientRect(hwnd, &clientRect);
			screenRatioX = (float)GAME_WIDTH / clientRect.right;
			screenRatioY = (float)GAME_HEIGHT / clientRect.bottom;

			output = true;

		return output;

I just have no idea how to do this in UE4.

I just wanted to add an update.
I am still having problems, I have been working with Rudy from Epic trying to get a resolution.
Here is my most current blueprint:

This is what I get if I try to run at my desktop resolution “2560x1600”


It appears to be offset by like 100 pixels or so.

The answer is here: