Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Get size of UMG widget

Hey, I want to get the size of a widget inside a child class of UHorizontalBox in C++. Is that possible? GetDesiredSize() always returns 0 and I hadn't have any luck with with anything else I tried so far.

Product Version: UE 4.10
more ▼

asked Jun 22 '16 at 08:50 PM in C++ Programming

avatar image

35 2 4 9

avatar image Pelangi Aug 09 '16 at 02:06 PM

I have this problem too in UE 4.12.

avatar image ElChipacabra Aug 25 '16 at 01:34 AM

I also have this problem in 4.11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I have found out, that there are two different approaches for this question.

  1. If you want to get the size during initialization of an actor, for example in BeginPlay, when the Geometry of the widget has not already been calculated, you can use the following code:

    UPanelSlot* examplePanelSlot = ExamplePanelWidget->Slot; UCanvasPanelSlot* exampleCanvasPanelSlot = Cast(examplePanelSlot); FVector2D examplePanelSize; if (NULL != exampleCanvasPanelSlot) { examplePanelSize = exampleCanvasPanelSlot->GetSize(); }

But this only works, if the UUserWidget* ExamplePanelWidget actually has an UCanvasPanelSlot, for example if you're using an Overlay or HorizontalBox.

You can see the kind of Slot in the UMG Blueprint, if you select the widget and go to the Details-Panel, for example:

alt text

2.:You can get the size during runtime from the Geometry of the widget:

   FGeometry cachedGeometry = ExamplePanelWidget->GetCachedGeometry();
   FVector2D currentSize = cachedGeometry.GetLocalSize();

But if you try this before the Geometry of the Widget was calculated the first time -- for example during BeginPlay -- you will get a zero vector.

more ▼

answered Apr 16 '17 at 11:56 AM

avatar image

26 1 2

avatar image Rumbleball Jul 04 '17 at 12:01 AM

I'm over this right now, as I want to fill a vertical box with as many text widgets as fit in without scrolling. But the size of the text can vary as well as the rendersize of the widget.

I got myself to the part with the cachedGeometry and that is 0 at time of building the widget (in RebuildWidget). But at what point is the geometry calculated? Can I force the calculation? The widget is placed in a WidgetComponent.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thanks, you are right

more ▼

answered Dec 10 '18 at 06:50 AM

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question