Reputation: 1
I am using QFormLayout but second item of row is not getting vertically wrapped.
.ui file content is
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>281</height>
</rect>
</property>
<layout class="QFormLayout" name="flPatientInfo">
<property name="rowWrapPolicy">
<enum>QFormLayout::WrapLongRows</enum>
</property>
<property name="verticalSpacing">
<number>5</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
Code where row is added -
for (auto info : patientInfo.toStdMap())
{
QLabel *fieldData = new QLabel(GetTranslatedString(info.second.second));
fieldData->setProperty("FieldData", true);
m_GUI->m_UI->flPatientInfo->addRow(GetTranslatedString(info.second.first), fieldData);
}
Actual Result
Expected Result
Upvotes: 0
Views: 265
Reputation: 11513
QFormLayout::RowWrapPolicy
has to do how labels and the widgets are layed out, not if the widgets should break. If the space available for label + widget is not sufficient, the widget is simply layed out in a new row when using QFormLayout::WrapLongRows
.
You add a QLabel
as the widget, which usually will not break text, but write in a single line. You need to enable word wrap on that label using setWordWrap
:
for (auto info : patientInfo.toStdMap())
{
QLabel *fieldData = new QLabel(GetTranslatedString(info.second.second));
fieldData->setProperty("FieldData", true);
fieldData->setWordWrap(true); // HERE
m_GUI->m_UI->flPatientInfo->addRow(GetTranslatedString(info.second.first), fieldData);
}
Upvotes: 0