Jump to content

[SOLVED] Resizing a GUI window to best fit


photo

Recommended Posts

Hi,

in 2.16.1, I have a window that only shows a GUI with some widget in it. The widget labels can change at runtime, so I need to resize the window so it won't clip the labels inside.

How can I resize the window to the best fit size? I tried EngineWindow::expand but it doesn't do what I expect.

Link to comment
2 hours ago, Amerio.Stephane said:

How can I resize the window to the best fit size?

// root widget for external window
auto root_widget = external_engine_window->getSelfGui()->getVBox(); 

// current content size
int content_width = root_widget->getWidth();
int content_height = root_widget->getHeight(); 

// current window size 
ivec2 windows_size = external_engine_window->getClientSize(); 

// now you need to choose the best size for your needs
if (windows_size.x < content_width)
	windows_size.x = content_width;
if (windows_size.y < content_height)
	windows_size.y = content_height;

// and apply new size to window size
external_engine_window->setSize(windows_size);

 

  • Like 1
Link to comment

It works perfectly!

Note: I added "root_widget->arrange()" on 2nd line to make sure the size were correct first.

This code sample could go straight to the doc!

Thanks!

Link to comment
  • bmyagkov changed the title to [SOLVED] Resizing a GUI window to best fit
×
×
  • Create New...