PDA

View Full Version : layout to fill all free space (vertical and horizontal)



Kees Bleijenberg
23rd June 2019, 23:13
I've stripped my problem to this simple case.
The main window has a vertical layout. A text edit is in that layout. At run time the text edit should adjust it's size to the width and height of the window.
The text edit adjusts it's width according to the form, but it's height does not.
I've changed the layout to a grid layout and I've tried all kinds of size policies, but the height of the text edit does not change if I change at run time the height of the window.

What I really want is a window with a tab widget at the bottom that adjusts it's width to the form. But the height of the tab widget should stay 100px, independent of the size of the window.
Above the tab widget is a plain text edit that fills all the free space on the form. And of course the user must be able to adjust the size of the window.
Is it possible to do this in qt creator?

Kees

anda_skoa
24th June 2019, 06:29
This should be the standard behavior of QTextEdit in a layout so there is likely something interfering or missing.

How did you create the layout? In code or with QtDesigner?
What is the base class of your window? QWidget, QMainWindow or something else?

Cheers,
_

Kees Bleijenberg
24th June 2019, 10:09
This should be the standard behavior of QTextEdit in a layout so there is likely something interfering or missing.

How did you create the layout? In code or with QtDesigner?
What is the base class of your window? QWidget, QMainWindow or something else?

Cheers,
_

Thank's for your answer.

It is a bit embarrissing.....

This is what I've tried in a new project:
I work only in QT creator
Starting with a new Widget Application,
I chose the kit Desktop Qt 5.12.1 MSVC 2017 64 bits
The main window inherits from QMainWindow
I open mainwindow.ui in the designer, drag a Text Edit and drop it on the window
then I right click on the window and chose layout, layout vertically
Now everything works as expected. Horizontal and vertical scaling works fine.

Then I removed everything from the window in my old project, removed the layout (right click, remove layout). Then I did exactly the same as in the new project. And the text edit failed to scale vertically.

The project is not very big yet. So I'll start again with the new project, still wondering what I did wrong.

Thanks
Kees

d_stranz
24th June 2019, 16:47
Try creating a plain QWidget as the central widget of the QMainWindow, adding your layout to that QWidget, and then adding your QTextEdit to that layout.

I don't usually create QMainWindow layouts in Qt Designer because my central widgets are usually complex - I do it in code in the QMainWindow constructor instead. But it could be that by default Qt Designer inserts a plain QWidget as the central widget, so just add the layout and text edit to that instead.