You are not logged in.

mthel

Beginner

  • "mthel" started this thread

Posts: 5

Occupation: Software Engineer

  • Send private message

1

Thursday, March 3rd 2005, 12:54am

Strange spacers behavior

I am fairly new to Qt, and have found a strange oddity in the way spacer's work in Qt Designer.

I have three labels, with a spacer in between each, like this
label1 <--spacer--> labe2 <--spacer--> label3

I then layout these 5 widgets horizonatally, and then layout the mainwindow as a grid.
What I expect to get is label1 on the left, label3 on the right, and label2 centered. Instead label2 is not centered? It seems to depend on the sizes of labels 1 and 3. If I force the labels to be the same pixel width, it works. But with different sizes, it doesn't.

Here is how it looks in Qt Designer


Here is how the application looks when run


The actual center point of the label is the "D" in "CENTERED".
The black arrow shows the actual center point of the window, which does not line up with the center point of the label.

Has anyone else seen this? Obviously I can just size the side labels the same and it works, but should I have to do this? Isn't this what spacers are for?

Thanks,
Keith

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Thursday, March 3rd 2005, 1:09am

Why should it be centered if label1 is wider than label3? Look that spacer sizes are equal and that is a proper behaviour. If you want label2 to be centered, resize label3 to have the same size as label1.

mthel

Beginner

  • "mthel" started this thread

Posts: 5

Occupation: Software Engineer

  • Send private message

3

Thursday, March 3rd 2005, 2:01am

It seems more logical to me that when a layout is used to expand widgets to fit the window size, the spacers would adjust to equalize the usage.

i.e. since there are three "non-spacer" widgets, the available space would be split into thirds, with each widget occupying the space required within their respective third.

What I guess I am after is a similar thing to the layout mechanism of GTK where you can set the horizontal and vertical layouts to be homogenous.

Keith

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Thursday, March 3rd 2005, 8:44am

You can change the behaviour of spacers by modifying their attributes. Another solution is not to use spacers at all, but rather order labels 1 and 3 to take all available space. I think this might work.

I think that default behaviour of spacers is sane, because it keeps proportions. Please note, that label2 is exactly in the middle between label1 and label3.

mthel

Beginner

  • "mthel" started this thread

Posts: 5

Occupation: Software Engineer

  • Send private message

5

Thursday, March 3rd 2005, 9:42pm

> You can change the behaviour of spacers by modifying their attributes. Another
> solution is not to use spacers at all, but rather order labels 1 and 3 to take all
> available space. I think this might work.

This almost worked, the label widgets on the sides were centered within the space they occupied.

> I think that default behaviour of spacers is sane, because it keeps proportions. > please note, that label2 is exactly in the middle between label1 and label3.

Indeed, if this is the way Qt works, then I shall use it as such. An idea came to me to at run time read the size of label1 and label3 and set the sizes to the maximum so they are the same.

Keith