Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Changing the order MapQuickItems are drawn on a Map
srce last edited by
I'm trying to change the order MapQuickItems are drawn, so I can control which item is on top, when two items overlap.
My map items are created in a C++ model that inherits from QAbstractListModel. It seems the items are normally drawn in the order they are in the model's list. So, I thought I could try reordering the items in the list, in order to control the order they are drawn. Is there a better/alternative way?
The results seem to vary on the way in which I reorder the items in the model.
If I call beginResetModel() before the move, it works, but it seems to be very slow (and seems a bit suboptimal to reset the entire model if only changing a few rows):
beginResetModel(); m_items.move(oldRow, newRow); endResetModel();
If I call beginMoveRows() instead,
beginMoveRows(parent, oldRow, oldRow, parent, newRow); m_items.move(oldRow, newRow); endMoveRows();
I get messages in the console of the form:
item QDeclarativeGeoMapQuickItem(0x1fe48ca0640, parent=0x0, geometry=449.254,281 66x18) still referenced declarativemaps\qdeclarativegeomapitemview.cpp: 475
If I try beginRemoveRows() followed by beginInsertRows()
beginRemoveRows(QModelIndex(), oldRow, oldRow); m_items.removeAt(oldRow); endRemoveRows(); beginInsertRows(QModelIndex(), newRow, newRow); m_items.append(text); endInsertRows();
Then this works if the item is moved to a latter index in the list, but not if moved to an earlier index.
emit dataChanged(index(oldRow), index(newRow));
afterwards doesn't seem to make any difference.
Perhaps it's an issue in my .qml, so I've put a simplified example here: Example project
Any ideas? Thanks.
6thC last edited by 6thC
Err... just use Z index? That's all I do anyway.
srce last edited by
Hmm - I had tried that, but couldn't get it working, but it seems to work in the cut down example I've created - so I guess I had another problem that was stopping it from working. Thanks.