QListWidgetItem items overlap each other

964 views Asked by At

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?

1

There are 1 answers

0
Ali Mofrad On

If you want to use setMinimumSize() for a QLabel, and QLabel has parent. use a QGridLayout as parent of your widget. layout apply minimum size of it's children.

if you don't want to use QGridLayout, you can setMinimumSize() for parent to proper value. this value is sum of minimum size of all it's children.