tags:

views:

49

answers:

1

Is there an easy way to ensure that controls in different groupboxes on a Qt dialog line up correctly using layouts? If not, is there a way to line them up using code in the dialog's constructor?

For example, here is a form with two groupboxes containing controls that are laid out using a grid:

alt text

Here is how I want it to look:

alt text

Note that these dialogs will end up translated into different languages so what might be the longest label in English won't necessarily be the same label in German.

+2  A: 

I don't think there is an easy solution since you have to separated and not connected layouts. What you could do is after you set up the layouts is iterating over all label strings and measure their size with QWidget::fontMetrics() on their label widget, remeber the maximum value and call QWidget::setMinimumWidth(). That you can also do after translating strings (if you do it dynamically at run-time).

Rupert Jones
OK, I did something similar using `sizeHint()` to find the longest label.
Rob
@Rob: True, that makes sense when you already have the QLabels constructed. If you plan to construct the labels from the strings, you could have iterate through the strings and measure their size with `fontMetrics()`, but I agree with `sizeHint()` in that case.
Rupert Jones