So I have QFormLayout that manages my QLabel-QLineEdit pairs just fine.
Problem is, that I need to achive something like this:
Horizontal border/tittle isn't a problem, but "Street"-"Apartment"/"Post code"-"City" pairs are.
So my question is: how to add two pairs of QLabel-QLineEdit as one row to QFromLayout?
If it's not possible with QFormLayout, do you have any suggestion about achivining the same with other layout (QGridLayout, I guess)?
Keep in mind, that labels can have different size proportions after translated to other languages.
Thanks in advance!
Thanks for all the response!
I've ended up adding QLabel as label and QHBoxLayout with QLineEdit, QLabel and QLineEdit as field to QFormLayout. Something like:
QLabel firstLabel, secondLabel;
QLineEdit fisrtEdit, secondEdit;
QHBoxLayout hBoxLayout;
hBoxLayout.addWidget(firstEdit);
hBoxLayout.addWidget(secondLabel);
hBoxLayout.addWidget(secondEdit);
QWidget container;
container.setLayout(hBoxLayout);
myFormLayout.addRow(firstLabel, container);
do the trick!
Also, if you're planing to add more than one row like this, I'll need to set all secondLabel
s to one fixed width. I did this by iterating over all secondLabel
s twice: first time for finding maximux width and second for setting this width to all of them.
A bit hacky, but I couldn't find a better way so far. Solution with QGridLayout would be even more complicated, on my opinion.
I think you should create a QWidget with get a Vertical layout with the QLabel and the QLineEdit then add the label in the QFormLayout. I don't get the time to show you an example but think about to create an ui with a QLabel-QLineEdit in a QVBoxLayout. By creating an ui you can add any widget in with the same form easily.
So you mainWindow. you main layout -> create your widget -> add vertical layout -> add your QLabel and QLineEdit to yout widget layout -> add your widget to your main layout.
I think you should show a QtCreator-QtDesigner tutorial. It will take you some time but you will get really faster after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With