I have a custom widget which has an overall layout of a QVBoxLayout. It contains several labels, a QFormLayout, a button, and a stretch to eat all excess space. One of the labels can be quite large so I am trying to ensure that there are no odd cases where the text is unreadable. The widget is contained within a QScrollArea to ensure that if the user shrinks the overall window all aspects of the widget can still be seen.
The QLabel appears to resize fine, but once it reaches a certain point of narrowness it just cuts off the bottom few lines of the label and allocates the space to the stretch at the bottom of the widget.
I am doing this all in code without the Designer, so it is entirely possible that I am just missing something. The subcomponents are added to the overall QVBoxLayout in the following order:
OverallLayout = new QVBoxLayout(this);
Title = new QLabel();
Description = new QLabel();
SubRegion = new QFormLayout();
Button = new QButton();
...
// set text values, wordWrap(true), and Font for labels
OverallLayout->addWidget(Title);
OverallLayout->addWidget(Description);
OverallLayout->addLayout(SubRegion);
OverallLayout->addStrut(MIN_DIST);
OverallLayout->addWidget(Button);
OverallLayout->addStretch(STRETCH_FACTOR);
Test results: Examining the results returned from the QLabel's sizeHint() function, the values returned do not appear to change as the widget is shrunk horizontally. However, the QLabel does expand to take up more vertical room (153 vs the hint of 103), just not enough to fit all of the text. When the QLabel is first shown, it has less pixels than its sizeHint but still enough for its heightForWidth amount. When it is resized, it has 30 less than its heightForWidth amount but more than its sizeHint.
I have checked and the large QLabel has its hasHeightForWidth() and wordWrap() values set to true. What am I doing wrong?
setMinimumHeight()
? – Ardy