PDA

View Full Version : Resizable Frames/Layouts



VireX
17th March 2007, 21:38
Hey, I couldn't find the answer while searching the forum, so I apologize if it's been brought up before.

I have a TreeView in one VBoxLayout, and then a TextEdit in a VBoxLayout on the bottom, I also have a TableView on the big box on the top left.
______
|---||--|
|__||--|
[__]|_|

Basically looks like that, if the spacing works out. Small text box on the bottom left. A Treeview covering the right half. And in the top left a large area of TableView.

What I need to do is, when someone resizes the whole window. I want them to be able to resize the TreeView, TextEdit, and TableView all at same time. Right now it stays the same size.

I can't post the large amount of code I created, as it would be confusing, but I understand your code, so if you know what functions to use, or a code example, it would be great, thanks.

wysota
17th March 2007, 21:43
Did you set a layout for the form itself?

jacek
17th March 2007, 21:46
Consider using a single grid layout.

VireX
18th March 2007, 00:19
I just AddWidget all three things? Then change the Column stuff? Any Examples?

THanks tho.

jacek
18th March 2007, 00:28
I just AddWidget all three things? Then change the Column stuff?
Yes.


Any Examples?

QGridLayout *l = new QGridLayout();
setLayout( l );
l->addWidget( _treeView, 0, 0 );
l->addWidget( _textEdit, 1, 0 );
l->addWidget( _tableView, 0, 1, 2, 1 );

VireX
18th March 2007, 01:23
setLayout is for some reason undefined. Maybe because my class is made with qtdesigner and is not an extension of QWidget? Also I changed the addWidget to addLayout.

What about QSplitter?

Since setLayout alone didn't work I did this...
The code in my setupUi() function: (qglMain = QGridLayout*)


qglMain->addLayout(vboxLayout, 0,0);
qglMain->addLayout(vboxLayout1, 1,0);
qglMain->addLayout(vboxLayout3, 0, 1, 2, 1);
MainWindow->setLayout(qglMain);

However, now it just crashes.
Commenting the setLayout line, still makes it crash.

wysota
18th March 2007, 01:39
What is "qglMain"? setLayout is defined in QWidget class, but we're assuming your widget is a widget :) if you create an ui in Designer, you later wrap it into a class inheriting QWidget (or one of its subclasses). That's the moment to put the above mentioned code. But if you use Designer, then simply click on the form (so that no items are selected) and click on "Lay out in a grid" icon in the toolbar.

jacek
18th March 2007, 01:44
Maybe because my class is made with qtdesigner and is not an extension of QWidget?
If you created it with Qt Designer, why do you need to add widgets to it? Can't you just add all of the widgets using Designer?

Also read this (http://doc.trolltech.com/4.2/designer-using-a-component.html) very carefully --- it explains how to use the code generated by uic.


Also I changed the addWidget to addLayout.
A single QGridLayout is enough in this case. There is no point in having layouts with only one widget inside (except for a top-level layouts). You can do the same using one QVBoxLayout and one QHBoxLayout (see below).


What about QSplitter?
You need two splitters. A horizontal one with tree view and text edit and a vertical one with the horizontal spitter and table view.


The code in my setupUi() function: (qglMain = QGridLayout*)
You shouldn't touch the code generated by uic.

VireX
18th March 2007, 01:49
I said qglMain = QGridLayout*..

Also I tried your designer trick... But now:
[_]| |
[_]|__|
It looks like it seperated everything into 3 boxes. It looks horrible, because the Treeview on the right is so big. I cannot change the size of the userlist, or any of the grid cells.

Why shouldn't I touch the code of ui, I want to change something I don't want to reopen designer and fix it, because it's something in the code.

Also, I tried the QSplitter approach, (yes I thought of 2 of them too) and then all my stuff just disappeared I couldn't see my results, just a blank window.
The QGridLayout approach, just makes my program crash. And using layouts in Designer sucks, so I like to code the layouts instead it's easier to see.

jacek
18th March 2007, 02:10
Also I tried your designer trick... But now:
[_]| |
[_]|__|
It looks like it seperated everything into 3 boxes. It looks horrible, because the Treeview on the right is so big. I cannot change the size of the userlist, or any of the grid cells.
Tweaking the hSizeType, vSizeType, horizontalStretch and verticalStretch properties for each widget should help.


Why shouldn't I touch the code of ui,
Because you will loose all changes when you change the .ui file.


I want to change something I don't want to reopen designer and fix it, because it's something in the code.
But you are fixing the results, not the causes.


Also, I tried the QSplitter approach, (yes I thought of 2 of them too) and then all my stuff just disappeared I couldn't see my results, just a blank window.
What did you do exactly? To add a splitter, you have to select two widgets and click "Lay out ... in Splitter". After you create all the splitters, you have to add a top-level layout.


And using layouts in Designer sucks,
No, it doesn't. You just have to learn how to use them.


so I like to code the layouts instead it's easier to see.
I think it's easier to see it on a live widget in the Qt Designer.

VireX
18th March 2007, 04:33
Yes you're right, it's easier to see it live. But some things I haven't learned to control yet, like layout, I keep trying to change the damn size on the splitter in Designer and can't do it. It won't let me push the center split to the right. I even tried the sizepolicy :
hSizeType, vSizeType, horizontalStretch and verticalStretch, when you change these nothing happens.
How do I move the splitters (horizontal) middle split to the right by like 200 px?

It keeps cutting off my long Text box at the bottom, and keeps the treeview so huge... Because it fixes the splitter so that it's centered in between both the widgets.

wysota
18th March 2007, 11:45
But some things I haven't learned to control yet, like layout,
It doesn't mean something sucks just because you haven't learned to use it.


I keep trying to change the damn size on the splitter in Designer and can't do it.
And you won't be able to. You can't control the initial size of the splitter - it'll adjust itself according to the widgets it holds.


It won't let me push the center split to the right. I even tried the sizepolicy :
hSizeType, vSizeType, horizontalStretch and verticalStretch, when you change these nothing happens.
Set the horizontalStretch of the left part to the same value as the horizontalStretch of the right part.


How do I move the splitters (horizontal) middle split to the right by like 200 px?
By using QSplitter::setSizes() in your code.


It keeps cutting off my long Text box at the bottom, and keeps the treeview so huge... Because it fixes the splitter so that it's centered in between both the widgets.

That's what you have size policies for.

wysota
18th March 2007, 11:56
Is the attached UI more or less what you wanted?

VireX
18th March 2007, 16:15
Almost, the table on the right is on the left, and the small corner box is suppose to be under the big one. It looks good tho.

VireX
18th March 2007, 16:23
It doesn't mean something sucks just because you haven't learned to use it.

No, because some programs have a steeper learning curve than others. They could have made it as simple as making tables in dreamweaver but decided that was not a good idea.
I didn't say it sucked anyway, I said it sucks to make layouts in it, which is true.


And you won't be able to. You can't control the initial size of the splitter - it'll adjust itself according to the widgets it holds.

Which is why I said it sucks making layouts.



Set the horizontalStretch of the left part to the same value as the horizontalStretch of the right part.

Adjusting horizontal stretch on either splitter 1 or 2, doesn't change a single thing. Neither does adjusting the sizes of the widgets, or adjusting the other sizePolicy values. They're basically useless in my situation. The splitter vertical line in the middle of my splitter 1 (horizontal) will not budge.



By using QSplitter::setSizes() in your code.

I thought you said I could do it in designer.



That's what you have size policies for.
Which don't work.

Also, listen, the untitled ui you gave me...
Has on one splitter horizontal stretch 1, the rest are 0 on both splitters. I don't understand why 1. And also changing those values doesn't change the layout at all. So I don't believe it controls size at all. Maybe if you tell me what exactly to change on each value to move the
middle split (vertical) to the right in splitter 2 (the total horizontal splitter) by 150 pixels, and the horizontal middle split in splitter 1 (the smaller vertical splitter) up by 100 pixels...

EDIT here:

wysota
18th March 2007, 18:09
I said it sucks to make layouts in it, which is true.
No, it's not :)


Which is why I said it sucks making layouts.
The problem is with QSplitter which is a widget, not a layout.



Adjusting horizontal stretch on either splitter 1 or 2, doesn't change a single thing.
Adjust the stretch before wrapping widgets into the splitter.


Neither does adjusting the sizes of the widgets, or adjusting the other sizePolicy values. They're basically useless in my situation. The splitter vertical line in the middle of my splitter 1 (horizontal) will not budge.
It will, preview or compile the widget and you'll see.


I thought you said I could do it in designer.
Yes, but you can't control everything - moving the splitter is one of the things you don't have total control over in Designer. You can adjust the sizes before applying a splitter though and they will hold.


Which don't work.
They don't work for you. They work quite fine for me :)


Also, listen, the untitled ui you gave me...
Has on one splitter horizontal stretch 1, the rest are 0 on both splitters. I don't understand why 1.
Hmm... AFAIR I set the stretch to "3" on the other widget and based on what I get when I preview the form it works correctly (meaning as if it was set to "3").


And also changing those values doesn't change the layout at all.
Splitter is not a layout but a widget. But anyway, you can achieve what you want by breaking the layout and applying the splitter again. I know it shouldn't be that way, it's a flaw, but it works with a little effort - it's only a glitch when displaying in Designer, when you compile the code, it'll work correctly.


So I don't believe it controls size at all.
Have you actually tried compiling the code?


Maybe if you tell me what exactly to change on each value to move the
middle split (vertical) to the right in splitter 2 (the total horizontal splitter) by 150 pixels, and the horizontal middle split in splitter 1 (the smaller vertical splitter) up by 100 pixels...

I can't give you "per pixel" instructions. Qt doesn't work that way. If you want "per pixel" sizes, use QSplitter::setSizes() from within the subclass when you already know the actual size of the widget. The size is impossible to determine from within Designer - it depends on the font used, etc.

Here is your ui:

VireX
18th March 2007, 20:38
Well that's just amazing; thanks a lot wysota as usual you help everyone a lot.

I'll try and use break layout and horizontal stretch before i apply widgets. Once I apply widgets nothing changes the positions/splits

Also on another note... Is it possible to add a pushbutton as an Item inside the TableWidget? Or should I have used Listview?

jpn
18th March 2007, 20:59
Is it possible to add a pushbutton as an Item inside the TableWidget? Or should I have used Listview?
You can use "item/cell widgets (http://doc.trolltech.com/4.2/qtablewidget.html#setCellWidget)" with convenience views and "index widgets (http://doc.trolltech.com/4.2/qabstractitemview.html#setIndexWidget)" with model-views.

wysota
18th March 2007, 22:46
I'll try and use break layout and horizontal stretch before i apply widgets. Once I apply widgets nothing changes the positions/splits

This is related to splitters only! For regular layouts you don't have to break the layout - stretches will take effect immediately regardless of when you change them (before or after applying a layout). The splitter issue is probably caused by the fact that widget size hints are not recalculated in Designer.

VireX
19th March 2007, 00:59
I see... anyway thanks. Now onward to learning about skins :).