Signal dataChanged breaks QListView in grid layout ?
-
Hello, I have a problem with a QListView in IconMode using a grid layout.
When displayed for the first time, everything works like a charm (http://hpics.li/afafe3d), but if the underlying model updates it's content (using signal dataChanged), the updated items don't respect the grid size policy (http://hpics.li/035dcbf). Using model reset, the layout keeps it's integrity (but it messes up the selection model).
Is this a bug or am I doing something wrong ?
QListView initialization:
//... ui -> listView -> setMovement(QListView::Static); ui -> listView -> setResizeMode(QListView::Adjust); ui -> listView -> setViewMode(QListView::IconMode); ui -> listView -> setGridSize( QSize(150, 100)); ui -> listView -> setWrapping(true); ui -> listView -> setWordWrap(true); ui -> listView -> setMinimumHeight(100); //...
Use dataChanged in model, breaks the grid layout:
//... int index = storageUnits.indexOf(unit); if(index >= 0) { QModelIndex idx = createIndex(index, 0); emit dataChanged(idx, idx); } }
Use reset in model, layout OK but impact other features of the app:
//... beginResetModel(); endResetModel();
-
Hi and welcome to devnet,
Can you create a minimal compilable example that shows this behavior ?
-
@SGaist Thanks for the quick reply. I posted a small example here.
On my box (running Linux and Qt5.4.1), clicking the button trigger the problem.
-
Looks like the word wrapping option gets killed somehow.
You should check the bug report system to see if it's something known. If not please consider opening a new bug report providing your code example with the corresponding pro file
-
For future reference, as a workaround we can implement SizeHintRole from the model to fix the view behaviour:
QVariant MyModel::data(const QModelIndex &index, int role) const { if(role == Qt::SizeHintRole) return QVariant(QSize(150, 100)); //.. }
-
Did you report the bug ?
-
Just reported it, here it is : https://bugreports.qt.io/browse/QTBUG-45427
-
Thank you very much