Initial size of widgets inside a QSplitter - qt

I have a vertical QSplitter with two widgets inside whose layouts contains more widgets. How can I set the initial height of the second widget to its minimum possible height (wrap to its content)?
Thanks in advance,

You can use QSplitter::setSizes to set widgets' sizes. You can obtain total available space using QSplitter::size. You can obtain minimal width of the second widget using QWidget::sizeHint. It will help you to calculate values that should be passed to setSizes.

Related

Does Qt's QLayout by default squezze/overlap all widgets on layout area?

If you implement for example a QHBoxLayout with a fixed width (determined by a parent layout) and add more widgets (with a given minimum size) than fit into the fixed layout area, the widgets are getting smaller than the minSize and at a certain point even overlap.
Is this (ignoring minimumSize, spacing) the default implementation?
If yes, how would you achieve to keep the minimumSize and "push" other widgets out of the layout area or only partially draw the widgets (clip to layout area)?
I came across what seems to be the c++ source code for the layout kernel. Layouts are calculated within the qLayoutengine. For GridLayouts, BoxLayouts that is done via internal qGeomCalc method. There it is stated: "It portions out available space to the chain's [chain: struct of layoutItems and its geometry] children". So minimumSize will get ignored in order to "pack" all items into the given space.

Is it possible to give a size by ratio to qt designer ?

For exemple, I want the value of the layoutLeftMargin property to be equal to 1/3 of the parent widget. So when I will resize the windows, the ratio of the widget will still stay the same.
Else, if it's not possible with QtDesigner, how can I do it with code ?
No, Margins are specified in pixels, they can't be relative to the parent widget's size.
However, You can do that in the designer by putting your whole current layout in a Horizontal Layout, add a Horizontal Spacer to the left of it, assign suitable layoutStretch values in the horizontal layout (In your example, this should be 1,2, meaning the original layout will take up twice the space taken up by the spacer, so that the spacer gets 1/3 of the parent widget).

Qt layout not expanding

I have a Qt Widget which has a frame, containg the rest of the widgets.
I only want one of the widgets to expand on maximazing the window, so I've set a max value for the others.
But it will only expand if I set a grid layout to the frame, which messes up the place of the widgets.
How can I solve it?
Do you use any kind of layout ?
Size policy only works if the parent has a layout set.
You can use a combination of different layouts to obtain the desired look, otherwise you will have to calculate the size of the 'expanding widget' yourself in the resize event method of the parent.

Qt: How do i set the height on a Vertical layout?

I'm having trouble using the layout manager system with Qt. This is going to be a Symbian app, so it should resize to different devices.
This is done by using the Layouts.
On the image below I used the Vertical Layout, but I don't understand how I can decide how much each cell should take in width and height.
I want the blue to be a top label background, but I don't want it to be as high as it is now.
Does anyone know how I can do this? (I'm new to Qt :))
You can set the maximum size for a widget by right clicking it and selecting 'Size Constraints'. Under that menu you can find actions that allow you to set the current displayed size as the maximum / minimum size for vertical / horizontal or both directions.
You can also set the numbers by hand by selecting the widget and by setting the number in the 'Property Editor'. They should be under the QWidget properties.
You cannot set the Height of a vertical layout directly, but you can set the height of the widget in which the vertical layout is.
If you want to split your Widgets so that the top widget takes 33.33% of the space, use the Stretch values. Set the top widget to 1 and the bottom widget to 2.

How to set default height on QTableWidget

I have a widget which I'm putting in a QVBoxLayout. This widget's layout is a QVBoxLayout which includes a QTableWidget. When I display this everything is fine but the QTableWidget only shows a few rows. How can I set the height of the table to a decent value (like 20 rows) while still allowing the table to resize?
I've tried calling table.setMinimumHeight(200) but then the table can NEVER be smaller than 200. I've also tried setting the container widget height using setMinimumHeight but this has the same problem.
Check the sizePolicy for the QTableWidget. This will have horizontal and vertical size policies which, if I understand you correctly, should be set to "expanding" or "minimum expanding". There are a number of options and combinations for these and sometimes it can be tricky getting the right combination for all the widgets in your layout to get what you are looking for.
The size policies will work in combination with your min/max height/width settings and those of the other widgets in the layout.

Resources