@Chris-Kawa said in Correct mode to draw UI:
The last line is too long because you've set a 2 column span on the horizontal layout, Just remove it:
Layout->addLayout(hl1, 3, 1);
Yes, this solution works fine :)
As for the widths - I don't know what SetWidgetWidth is, but you can remove it and just set some stretch factors, for example:
hl1->setStretchFactor(leZip, 1);
hl1->setStretchFactor(leCity, 10);
hl1->setStretchFactor(leProv, 1);
The 1,10,1 ratio is just an example. You can set it to be whatever you want.
Alternatively you can fix the size of the side line edits and set the central one to expanding:
SetWidgetWidth estimate width of widget about max string lenght.
This is the function:
void GenericDialog::SetWidgetWidth(QLineEdit *LineEdit, uint16_t len)
{
QString StrLen;
for(uint16_t s = 0; s <= len; s++) StrLen += 48+s;
QFontMetrics fm(LineEdit->fontMetrics());
LineEdit->setMinimumWidth(fm.horizontalAdvance(StrLen));
}
I tried to use setStretchFactor, but leZip and leProv still too large.
If I increase width of window, leZip, leCity and leProv increase his width in equal measure.
leZip->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
leCity->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
leProv->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
With setSizePolicy (that I had already tried) leZip and leProv continue to still too large.
It seems that under this measure they cannot be set.
Also, just a side note: just as all indexing in C++, row numbers start at 0. You added widgets to rows 1, 2 and 3, so you have an empty row at the top of the layout.
Yes, you are right, but the posted code is a small part of a larger function with other controls above.