I have defined a widget, which contains a QLabel (and other elements) that should show wrapped text.
This QLabel has:
Horizontal Policy: Minimum
Vertical Policy: MinimumExpanding
WordWrap: true
The widget has:
LayoutSizeConstraint: SetMinimumSize
Other than that a I have another widget which contains QListWidget item. I want to add the widget with QLabel as many times as I want. To do that I use a helper:
QListWidgetItem* showWidgetOnTheList(QListWidget* view, QWidget* widget)
{
QListWidgetItem *item = new QListWidgetItem(view);
QSize size(view->size().width(), widget->height());
item->setSizeHint(size);
view->addItem(item);
view->setItemWidget(item,widget);
return item;
}
The final result is that I see elements which overlap each other. What is the proper solution?
If you want to use
setMinimumSize()
for aQLabel
, andQLabel
has parent. use aQGridLayout
as parent of your widget. layout apply minimum size of it's children.if you don't want to use
QGridLayout
, you cansetMinimumSize()
for parent to proper value. this value is sum of minimum size of all it's children.