views:

36

answers:

1

Hello,

On a form designed with Qt Designer, I have two QGroupBoxes with a bunch of controls in each of them. Both group boxes have nearly the same contents (QLineEdits with associated labels).

What I want to do, however, is to align the controls together, as if they were part of the same grid layout. But since they are in separate containers, they can't share the same layout, and I don't want to give them a fixed width.

Is there a way to do it in Qt Designer? If not, is there a way to do it in code?

Thanks!

+2  A: 

There is no way to do this in Designer. As far as I know, Qt does not provide a good way to do this in code either. If you really want this, you will probably have to rely on something a little hacky.

Here's my first idea: Override resizeEvent() in the widget that contains the two group boxes to get the preferred size (via sizeHint() or minimumSizeHint()) of all of the labels and set the fixed width of all the labels to the largest preferred width.

I would encourage you to ask yourself if this really matters (is it worth the development time?) and consider whether you can avoid the problem entirely with a slightly different UI design.

BTW, you might want to take a look at QFormLayout if you haven't already.

Steve S