How to update QListWidgetItem geometry.
-
wrote on 13 Mar 2017, 11:41 last edited by
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? -
wrote on 14 Mar 2017, 13:14 last edited by
Hi,
it will probably work if you remove the item and add it again with the different size hint.
-Michael. -
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.
-
wrote on 15 Mar 2017, 08:44 last edited by
The widget
sizeHint
is probably not that important to the QListWidget.It might be worth switching to a custom delegate instead... see QStyledItemDelegate
-
wrote on 15 Mar 2017, 10:00 last edited by tokafr
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.
1/5