Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preview sizes of widgets in layout before a show()?

Tags:

qt

How do I preview what the size of widgets in a window will be after the layout rules are applied, before I actually show() the widget window? It seems all sizes are 100x30 before that initial show() command. How do I go around that?

like image 539
JasonGenX Avatar asked Feb 10 '11 21:02

JasonGenX


People also ask

How do I find the size of a widget?

There is no direct way to calculate the size of the widget, so to find that we have to take the help of the context of the widget. Calling context. size returns us the Size object, which contains the height and width of the widget. context.

What is the difference between widget and layout?

Layouts are an elegant and flexible way to automatically arrange child widgets within their container. Each widget reports its size requirements to the layout through the sizeHint and sizePolicy properties, and the layout distributes the available space accordingly.

How do I change the size of a widget in Qt?

Custom Widgets in LayoutsReimplement QWidget::sizeHint() to return the preferred size of the widget. Reimplement QWidget::minimumSizeHint() to return the smallest size the widget can have. Call QWidget::setSizePolicy() to specify the space requirements of the widget.

How do you get the available height in flutter?

How do you find the height and width of a Flutter percentage? double height = MediaQuery. Container( height: height * 0.1, //height to 10% of screen height, 100/10 = 0.1 width: width * 0.7, //width t 70% of screen width color: Colors.


2 Answers

The invalidate() worked for me.

Notice that if you do the following it would work as asked here (at least it seems to be fine in my code):

widget->show();
widget->layout()->invalidate();
widget->hide();

This doesn't show the widget on the screen since you don't relinquish control back to the queue until the hide() happens. In between, the invalidate() computes the correct positions.

like image 157
Alexis Wilke Avatar answered Oct 11 '22 14:10

Alexis Wilke


For me, the following worked:

window->layout()->update()
window->layout()->activate()

This probably does the same as Alexis' answer but it doesn't require showing-then-hiding the window.

like image 27
JanKanis Avatar answered Oct 11 '22 13:10

JanKanis