3

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?

Ali Mofrad
  • 308
  • 5
  • 21
Peter
  • 31
  • 3
  • The cause of the problem is QLabel which does not return proper size (when wordWrap flag is on) as long as it is not shown. There is a workaround: I can call on layout, that this QLabel belongs to, two methods: invalidate() and activate(). – Peter Nov 18 '14 at 14:08

1 Answers1

1

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.

Ali Mofrad
  • 308
  • 5
  • 21