Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Changing the order MapQuickItems are drawn on a Map
Forum Update on Monday, May 27th 2025

Changing the order MapQuickItems are drawn on a Map

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 416 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srce
    wrote on last edited by
    #1

    Hi,

    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.

    Calling

    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.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by 6thC
      #2

      Err... just use Z index? That's all I do anyway.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        srce
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved