Synchronize QFormLayouts (i.e. width of labels and widgets)
-
Ok, I see what you mean. Currently (unless you want to create your own layout class which would be the cleanest way) the only not so dirty hack I can think of would be to get the widest string from both form layouts and then pad one of the other layout with spaces to match the longest.
Hope it helps
-
That's "not so dirty"? Now I am interested to see what you consider dirty.^^
In addition my application can be translated, so static solutions are impractical.Writing a custom layout might be the only real solution. If the different layouts cached their maximum label-width in a way that would be accessible from "friend" layouts, this might even be doable. But I suspect that these details are hidden in private classes and this seemingly easy thing will get really ugly and/or difficult.
I also wouldn't know how to use a custom layout in Qt Designer, I am fairly new to it.Is there something like a static variable that can only be accessed by some instances of a class instead of all?
-
No you're not ;)
You can also use a QGridLayout, more code but you have more control over the row/col setup
-
Yes, I know. But I have had this problem with QFormLayout before and I thought I am just missing something - it looks like the form layout is mostly useless to me, no matter how much I like its simplicity. Can one request features somewhere?^^
Also, I am not too sure if a grid layout wouldn't suffer from the same problem... if I had to hardcode the widths of columsn, it wouldn't be much better than the form layout I am using currently.
PS: "I am not?" - what was that refering to?
-
Feature request can be done on the "bug report system":http://bugreports.qt-project.org :)
With the grid layout, you can play with span and stretch factor
You're not interested by what I consider dirty hacks ;)
-
[quote author="thEClaw" date="1400572586"]Also, I am not too sure if a grid layout wouldn't suffer from the same problem[/quote]
No it not suffer :-) See "QGridLayout::setColumnMinimumWidth":http://qt-project.org/doc/qt-4.8/qgridlayout.html#setColumnMinimumWidth
Also for form layout you could set the minimum width of all labels
@
foreach (QLabel* label, yourDialog->findChildren<QLabel*>())
label->setMiminumWidth(hack_number)
@ -
I seemingly need an additional account for the bug report system. Maybe...
Setting a minimum width still is not as flexible as a form layout. As I said, translations are an option, and those might exceed the minimum width of one or several layouts (so the result would not be aligned again).
I might go the "custom layout route". Or just be angry with Qt for a day or two and then accept my fate.
-
[quote author="thEClaw" date="1400574466"]translations are an option, and those might exceed the minimum width of one or several layouts (so the result would not be aligned again).[/quote]
Ok, so you know the maximum width of every label text:
@
QFontMetrics fontMetrics(label->font());
int width = fontMetrics.width(label->text());
@ -
I don't get your thoughts. From my point of view, this "hack" will work seemly.
Other alternative in your Ui design is to remove the group-box and layout the entire dialog in a form layout. Instead of having group box, place a single QLabel with a bold text to mimic the group box
edit: instead of QLabel I saw you have QCheckBox. So you can put a check box and enable/disable the controls programatically