[Qt-interest] QLayout: Aligning elements with some elements outside and some elements inside of a widget

Andre Somers andre at familiesomers.nl
Fri Dec 3 07:49:04 CET 2010


Op 3-12-2010 0:21, micu schreef:
> Hi there,
>
> I am new to this list and new to Qt --- so please excuse me, if my
> questions are a bit stupid ;).
>
> I created a custom widget, which includes a name in a title bar, some
> connector names (QLabels), and some connector icons (I took radio
> buttons in this case). These connector names are inside of a QFrame,
> while the connector icons are outside of the QFrame --- see attached
> picture.
>
> Now I want those connector icons to be aligned horizontally with the
> corresponding connector names (QLabels). I achieved a similar result
> with a workaround with QLayouts (see attached picture), but the
> alignment isn't perfect, as the frame of the QFrame takes a bit of the
> place.
>
> Is there any (preferable, "Qt-like") way of doing this that results in
> perfect alignment of connector name labels and connector icons? More
> generally asked: Is there a way of aligning widgets/layouts within
> another widget and widgets/layouts outside of that widget?
That is in interesting question, but I fear the answer is no, there 
isn't a way to do that. Not with the standard layouts, at least.
Your best bet to keep items aligned, is to make sure the items are a 
unit. That means that you'll have to rethink the construction of your 
form a bit. Keep the names in a layout with their connector, and build 
up from there. However, I don't think your layout is quite compatible 
with Qt's layout system. You may have to resort to manual positioning of 
widgets.

The layoutsystem that you can use in QGraphicsView 
(QGraphicsAnchorLayout) and QML seem to be better suited for this kind 
of use case.

André




More information about the Qt-interest-old mailing list