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. Map Touch Issue in Qt QML

Map Touch Issue in Qt QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 372 Views 2 Watching
  • 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.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote on last edited by serkan_tr
    #1

    I created a Map in Qt QML and placed buttons and a Toolbar on top of it. However, when I tap on the pop-up windows that appear after pressing the buttons or toolbar, I noticed that the Map in the background still receives the touch events. I tried adding a MouseArea to the pop-up windows to prevent this, but nothing changed. What kind of adjustment should I make in this case

    main.qml

    .
    .
    .
    
     MapView {
                visible: isLogin
                id: mapViewId
                z: -1
            }
    
            Toolbar {
                id: toolbarId
                visible: isLogin
                anchors {
                    top: parent.top
                    horizontalCenter: parent.horizontalCenter
                    topMargin: height / 10
                }
            }
    
            WidgetLayer {
                id: widgetLayerlId
                visible: isLogin
                anchors {
                    top: toolbarId.bottom
                    right: toolbarId.right
                    topMargin: buttonWidth * 0.2
                }
            }
    
            Loader {
                id: pageLoader
                anchors.centerIn: parent
            }
    .
    .
    .
    

    Toolbar .qml

    import QtQuick
    import QtQuick.Controls
    import QtQuick.Layouts
    import QtQuick.Dialogs
    import Qt5Compat.GraphicalEffects
    
    
    Rectangle {
        id: toolbarRoot
    
        width: parent.width * 0.98
        height: parent.height * 0.08
        radius: height / 4
        color: Qt.rgba(0, 0, 0, 0.80)
    
        Rectangle {
            id: logoRec
            width: parent.width * 0.12
            height: parent.height * 0.5
            color: mainColor
    
            Image {
                id: image
                source: "/images/lectron.png"
                anchors.fill:       parent
                fillMode: Image.PreserveAspectFit
            }
    
            ColorOverlay {
                anchors.fill:       image
                source:             image
                color:              "white"
            }
    
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    pageLoader.source = "SettingsPage.qml"
                }
            }
    
            anchors{
                verticalCenter: parent.verticalCenter
                left: parent.left
                leftMargin: height
    
            }
        }
    
        Text {
            id: timeText
            text: _TimeManager.clock
            font.pointSize: fontSize * 1.5
            anchors.centerIn:  parent
            color: "white"
        }
    
        Text {
            id: vehicleInfoText
            text: qsTr("Locked")
            font.pointSize: fontSize * 1.4
            anchors {
                verticalCenter: parent.verticalCenter
                left: timeText.right
                leftMargin: parent.width * 0.2
            }
            color: "yellow"
        }
    
        Rectangle {
            id: batteryFrame
            width: height * 0.6
            height: parent.height * 0.5
            border.color: "white"
            border.width: 2
            color: mainColor
            anchors {
                verticalCenter: deviceChargeText.verticalCenter
                right: deviceChargeText.left
                rightMargin: parent.height * 0.2
            }
    
            property real innerWidth: width - border.width * 4
            property real innerHeight: height - border.width * 4
    
            Rectangle {
                id: batteryLevel
                width: batteryFrame.innerWidth
                height: (batteryFrame.innerHeight * _BatteryStatus.charge) / 100
                x: batteryFrame.border.width * 2
                y: batteryFrame.height - batteryFrame.border.width * 2 - height
                color: "white"
                radius: 2
                onHeightChanged: {
                    y = batteryFrame.height - batteryFrame.border.width * 2 - height
                }
            }
        }
    
        Rectangle {
            width: height * 2
            height: batteryFrame.height * 0.1
            color: batteryFrame.border.color
            anchors.bottom: batteryFrame.top
            anchors.horizontalCenter: batteryFrame.horizontalCenter
        }
    
        Text {
            id: deviceChargeText
            text:  "%" + _BatteryStatus.charge
            font.pointSize: fontSize * 1.3
            color: textColor
            anchors {
                verticalCenter: parent.verticalCenter
                right: parent.right
                rightMargin: parent.height * 0.2
            }
        }
    
        Connections {
            target: _SerialManager
            function onDeviceConnected(device)
            {
                vehicleInfoText.color = "lime"
                if(device == 1)
                {
                    vehicleInfoText.text = qsTr("Stand")
                }
                else if(device == 2)
                {
                    vehicleInfoText.text = qsTr("Drone")
                }
                else if(device == 3)
                {
                    vehicleInfoText.text = qsTr("Simulation")
                }
            }
            function onDeviceDisconnected()
            {
                vehicleInfoText.text = qsTr("Locked")
                vehicleInfoText.color = "yellow"
            }
    
    
        }
    }
    
    

    MapView.qml

    Item {
        id: mapRootId
    
        anchors.fill: parent
        property bool isReconnect: false
      PositionSource {
            id: positionSource
            active: true
            updateInterval: 1000 // Update position every 1 second
            onPositionChanged: {
                if (positionSource.position) {
                    map.center = positionSource.position.coordinate;
                }
            }
        }
    
        Map {
            id: map
            anchors.fill: parent
    
            plugin: mapPlugin
            center: QtPositioning.coordinate(39.93, 32.89)
            zoomLevel: 14
            property geoCoordinate startCentroid
            activeMapType: map.supportedMapTypes[supportedMapTypes.length - 1]
    .
    .
    .
    
    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zvoopz
      wrote on last edited by zvoopz
      #2

      Make popup windows modal
      https://doc.qt.io/qt-6/qml-qtquick-dialogs-dialog.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kai Nickel
        wrote on last edited by
        #3

        It's a bug, it's complicated:

        • https://bugreports.qt.io/browse/QTBUG-115141
        • https://bugreports.qt.io/browse/QTBUG-107994

        One workaround would be to set a TapHandler in the popup to consume the events.

        1 Reply Last reply
        1
        • serkan_trS serkan_tr has marked this topic as solved on

        • Login

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