As it turns out - using QSpacerItem for this task is not so trivial, at least not to me...
At this point, you probably figured out what I am trying to do.
I have a DWORD (which is actually a LineEdit - a subclass of QLineEdit), of width W points.
The DWORD's "Fields Layout" (not to be confused with Qt's Layout Managers) is a QVector describing the breakdown of the DWORD:
typedef std::pair<QString, int> Field;
typedef QVector<Field> FieldsLayout;
Where the QString is the name of the Field, and int is its bit-size.
Assume that an instance of FieldsLayout always sums up to 32. In other words:
// let 'fieldsLayout' be an instance of FieldsLayout
int sum = 0;
for (int i = 0; i < fieldsLayout.size() i++) sum += fieldsLayout[i].second;
assert(sum == 32); // this assertion never fails
Now suppose 'labels' is an instance of QVector<QLabel*>:
QVector<QLabel*> labels;
for (int i = 0; i < fieldsLayout.size() i++) labels.push_back(new QLabel(fieldsLayout[i].first))
Given the above, my goal is to have labels[i] span over fieldsLayout[i].second * W/32 points, and be positioned above its corresponding bits in the DWORD.
Something along the line of:
[image: aa58e59c-4595-4138-84b7-722928764483.png]
Maybe I don't even need QSpacerItems? Maybe all I need is making sure that each QLabel spans over the correct amount of W/32?
If so, how can that be achieved?
Please advise.
Thanks!
CORRECTION
I don't want the QLabel to span over the correct amount of W/32 (I just realized it's easy - all I need is to set the QLabel to a fixed size of fieldsLayout[i].second * W/32), but rather I want it to be positioned in the center of the correct amount of W/32:
[image: 696a96d3-7215-4fe1-8f0f-2b8bde91c43f.png]
(The QLabel should take the minimum size it needs to display the text, and to be in the center of fieldsLayout[i].second * W/32 space)