Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Moving qml Map from first SplitView to second SplitView using takeItem and addItem



  • Hello everybody! For my special use case i need to "reparent" content(QML Map) from one splitView to another and I try to to it this way

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    import QtLocation 5.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Plugin {
               id: mapPlugin
               name: "osm"
        }
    
        Button{
            z: 1
            onClicked: {
                const a = first.takeItem(0)
                second.addItem(a)
            }
        }
    
        SplitView {
            id: first
            width: parent.width
            height: parent.height / 2
            orientation: Qt.Horizontal
    
            Rectangle {
                color: "lightblue"
                SplitView.preferredWidth: 320
                   Map {
                       anchors.fill: parent
                       plugin: mapPlugin
                       center: QtPositioning.coordinate(59.91, 10.75) // Oslo
                       zoomLevel: 14
                   }
            }
            Rectangle {
                SplitView.preferredWidth: 320
                color: "lightgray"
            }
        }
    
        SplitView {
            id: second
            anchors.top: first.bottom
            width: parent.width
            height: parent.height / 2
            orientation: Qt.Horizontal
    
            Rectangle {
                color: "lightgreen"
                SplitView.preferredWidth: 320
            }
        }
    }
    

    If the movable rectangle holds a map inside than(after clicking the button) the app freezes for 1-2 seconds and closes without printing any errors or another messages in console. This happens only with map.

    Also I noticed if the movable rectangle has zero width and I do not touch the splitter(make map rectangle width greater) the transfer is success.

        Rectangle {
                color: "lightblue"
                SplitView.preferredWidth: 0
                   Map {
                       anchors.fill: parent
                       plugin: mapPlugin
                       center: QtPositioning.coordinate(59.91, 10.75) // Oslo
                       zoomLevel: 14
                   }
            }
    

    Any ideas how to manage this problem?

    Thank you!


Log in to reply