How to update QListWidgetItem geometry.

  • Hello
    I am using QListWidget to have a list of widgets. to fill this list I use QListWidgetItem and set sizeHint to it.

    listWidget_ = new QListWidget(this);
    void addWidgetToList(QWidget *widget)
        QListWidgetItem wItem  = new QListWidgetItem(listWidget_);
        wItem -> setSizeHint(widget -> sizeHint());
        listWidget_ -> addItem(wItem);
        wItem -> setItemWidget(widget);

    on other part of code I need to change the sizeHint of items and I set different sizeHints to all items in list.
    but they don't update the geometry but wItem -> sizeHint() shows new correct value.
    I tried to call update, layout() -> invalidate/activate, updateGeometry repaint but they didn't affect.
    any idea?

  • Hi,
    it will probably work if you remove the item and add it again with the different size hint.

  • Lifetime Qt Champion


    Why not use a QScrollArea for that ?

    A container QWidget with a QVBoxLayout on it and you have pretty much the behavior you want without having to play with the item size hint.

  • The widget sizeHint is probably not that important to the QListWidget.

    It might be worth switching to a custom delegate instead... see QStyledItemDelegate

  • Well seems that it needs to emit model's layoutChanged() to do what I need. I created new class which inherits QListWidget and there I connected signal to layoutChanged signal of model() object and it worked.

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.