PDA

View Full Version : Putting Widgets into a Layout



jcoop
11th April 2009, 02:20
I've got a few widgets (a PushButton, CheckBox and ScrollBar) that I need to put into a window, aligned at the bottom. In my fiddling around with the Grid and Box layouts, the widgets always get piled on top of each other, or squished into a corner, or end up with really odd dimensions. How can I hardcode size and location values for each of them and then add them to the window?

wysota
11th April 2009, 09:04
You can but it's not advised, so I won't tell you how :)

Instead use QBoxLayout::addStretch(), QBoxLayout::addSpacing() and size policies to place the widgets inside a layout correctly. If you provide an image of a mockup of what you want to achieve, we'll help you with that.

jcoop
13th April 2009, 04:24
http://web.engr.oregonstate.edu/~coopejud/demo.bmp

That's pretty much it. The drawing part is easy, but the widgets are a pain, and I haven't even attempted to display the picture.

Help would be greatly appreciated. :cool:

lyuts
13th April 2009, 10:55
Try smth like this


QGridLayout *layout = new QGridLayout;

layout->addWidget(Graphic, 0, 0, 1, 3);
...
layout->addWidget(PushButton, 2, 0);
layout->addWidget(CheckBox, 2, 2);

wysota
14th April 2009, 15:54
http://web.engr.oregonstate.edu/~coopejud/demo.bmp

That's pretty much it. The drawing part is easy, but the widgets are a pain, and I haven't even attempted to display the picture.

Help would be greatly appreciated. :cool:

Here is a UI file with what you want to achieve. Be sure to view it with a style that supports full styling (every style except WindowsXP, WindowsVista and Aqua) to see the colours from your mockup.

Chisum
14th April 2009, 17:44
I am also have some trouble learning to do layouts in Qt Creator. I have included the ui file I am working on. By applying the grid layout to the whole form, I have gotten a lot closer to what I am attempting to do. The form does now resize correctly, for the most part. My problem is that I want the table widget on the left and its pushbuttons to not resize, while the right table and its pushbuttons will expand when resized. Is this possible? Or should I be content with what I have.

I would appreciate any assistance. I am keeping notes on the information I am getting on using layouts and I hope to create a topic on the wiki to help us 'newbies' get up to speed on this.

The file I have uploaded does not have any layouts applied.

gary

ps: I am not as smart as the trolls, but I do like lutefisk.

http://www.davethefox.com/words/0112lutefisk.htm

wysota
14th April 2009, 22:05
Is this what you wanted? Note the size policy of the left view and the size constraint of the layout it is placed in.

In general read about layouts and size policies.

Chisum
14th April 2009, 22:14
Well, I have continued to work on my layout problems and I have created a version which is very close to what I want. I have included it below. A quick review of some things I learned include:

It is possible to teach an 'old dog' new tricks but it does take time.

I will expand on my work over the next few days, and share it with all of you newbies. My goal is to provide an easy to follow set of steps to achieve this.

I do have a few issues with the documentation in Qt Assistant. Specifically, when choices like (Fixed, Preferred. et al) are not really explained. For starters, examine the Size Policy values.

Now, it is time to kick back...

gary

Chisum
14th April 2009, 22:28
Just a more personal thank you to wysota. I was composing my last post when you posted yours. My wife is Polish-American, so we have great love and respect for all things Polish. I really do love this site, it is one of the best programming sites I have seen.

Good Luck with your studies and work.

gary

wysota
14th April 2009, 22:43
I do have a few issues with the documentation in Qt Assistant. Specifically, when choices like (Fixed, Preferred. et al) are not really explained. For starters, examine the Size Policy values.

They are explained here and there but I understand it may not be very clear for everybody. I've been meaning to prepare a video tutorial on layouts and size policies but I either lack motivation or time. When (if) I have both at the same time, I'll post the results.

Chisum
15th April 2009, 17:07
wysota - I would like to write up a wiki type how-to on some of the basics of using layouts, particularly using layouts in Qt Creator. It would provide some of the basic information I have learned from my experiences with Designer. I enjoy colloborative efforts and I have the time to do it.

gary

wysota
16th April 2009, 00:02
Please do that but don't mention "Qt Creator". Creator is just a wrapper over Designer when it comes to designing user interfaces so it's better to say "Designer" than "Creator" in this context.

Chisum
16th April 2009, 21:47
wysota:

I uploaded the file below to the wiki. Not sure I did it correctly, so here is a rough draft of the file as well. Please feel free to edit it, brutally if necessary.

Also any one else who might what to change or add to it, please feel free to do so.

It is my first attempt at a wiki article.

gary

wysota
17th April 2009, 07:55
What wiki did you put it in? It's not our wiki for sure, it hasn't been updated for two weeks...

Chisum
17th April 2009, 17:46
wysota

I went to the Wiki shown at the top of the forum, logged in, and then went to the 'Uploadfile' page, and then completed the form. I really have not done a page on a wiki before. Where should I go? It sounds like I need to write up my experiences with 'Creating My First Page' for the wiki. lol

It may be that I screwed up the 'Destination filename'. I did add a brief summary.

gary

Chisum
18th April 2009, 04:51
wysota

Well, I have created a page within my 'user talk' and saved it. I am still not clear if that is the right way to create a page.

gary

wysota
18th April 2009, 22:00
It's not :)

Follow this link:
http://wiki.qtcentre.org/index.php?search=Using+layouts+with+Designer
and click on "Create this page".