From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


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.
    -Michael.


  • Lifetime Qt Champion

    Hi,

    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.


  • Qt Champions 2018

    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.