How to set different size of layouts in Qt?
-
I put on the central widget QHBoxLayout in Qt Designer. Then I put 2 QVBoxLayout's in this QHBoxLayout. They occupy the space of equal width, as can be seen in the Picture.
The question is: how to make them of different width? For example, 1:3 (left QVBoxLayout width : right QVBoxLayout width).
And how to make it in Qt Designer and from the source code?
What is layoutStretch field on the right bottom of the picture and how to use it?
Could You, please, give some code example. -
How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?
-
I put on the central widget QHBoxLayout in Qt Designer. Then I put 2 QVBoxLayout's in this QHBoxLayout. They occupy the space of equal width, as can be seen in the Picture.
The question is: how to make them of different width? For example, 1:3 (left QVBoxLayout width : right QVBoxLayout width).
And how to make it in Qt Designer and from the source code?
What is layoutStretch field on the right bottom of the picture and how to use it?
Could You, please, give some code example. -
How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?
-
How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?
-
How to use it? It doesn not work in my Qt Designer, or I do not understand something. Have not found any proper explanation on the Internet yet. Could You, please, give any link? And how to do it from the code?
@And92 said in How to set different size of layouts in Qt?:
Could You, please, give any link? And how to do it from the code?
Start from https://doc.qt.io/qt-5/qboxlayout.html#setStretch, and other references to
stretch
on that page and elsewhere, like https://doc.qt.io/qt-5/layout.html#stretch-factors. Also, once you have setlayoutStretch
in the Designer, you can look in theuic
-generated code (ui_*.h
files) to see what statements that is producing at run-time. -
Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
@JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
Unfortunately, I do not know how to mark the answer as a solution here. -
Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
@JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
Unfortunately, I do not know how to mark the answer as a solution here. -
Thank You very much, @Bonnie and @jsulm, I got the idea. It is simple. My error was that i tried to set layoutStretch property in both of QVBoxLayout, but should modify the layoutStretch property of the QHBoxLayout layout, containing them.
@JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
Unfortunately, I do not know how to mark the answer as a solution here.@And92 said in How to set different size of layouts in Qt?:
@JonB, I have alredy seen these links. But there are no code examples illustrating how to use those functions.
https://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html
http://zetcode.com/gui/qt5/layoutmanagement/Sorry, but I didn't write the Qt docs :), that's what I could spot.