Amerio.Stephane Posted June 8, 2023 Share Posted June 8, 2023 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
cash-metall Posted June 8, 2023 Share Posted June 8, 2023 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); 1 Link to comment
Amerio.Stephane Posted June 8, 2023 Author Share Posted June 8, 2023 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
Recommended Posts