小编nfr*_*lin的帖子

QML-maps:点击屏幕时获取坐标

我正在使用 Qt Creator(社区)5.5.1 制作项目并支持 QML。我有这个代码:

主.qml:

MouseArea
        {   anchors.fill: parent
            onPressed: console.log('latitude = '+ (map.toCoordinate(Qt.point(mouse.x,mouse.y)).latitude),
                                   'longitude = '+ (map.toCoordinate(Qt.point(mouse.x,mouse.y)).longitude));
Run Code Online (Sandbox Code Playgroud)

所以当我点击屏幕时,地图上这个地方的坐标会显示在控制台上。但我不知道如何使用这些坐标在发生点击的屏幕上定位标记。这是标记代码:

MapQuickItem {
        id:marker
        coordinate:  QtPositioning.coordinate(******, ******);//stars are the coordinates
        sourceItem: Image{
            id: image
            source: "marker2.png"

        }
        anchorPoint.x: image.width / 2
        anchorPoint.y: image.height

    }
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能将标记定位在地图上发生点击的坐标处?谢谢。

c++ maps qt android qml

5
推荐指数
1
解决办法
4530
查看次数

QML用计时器移动文本

我需要在屏幕上从右到左连续创建移动文本,我已经使用QML TimerText元素实现了它.

下面的代码工作正常,但我担心下面的代码导致更多的CPU或内存使用主要是因为定时器每33毫秒触发一次.我必须在我的应用程序和多个实例中使用它,例如在许多网格窗口内.

这是正确的方法吗?或者有什么比这更好的吗?

Rectangle{
        width:parent.width
        height:parent.height
        color: "#333333"

        Timer {
            id: resetTimer
            interval: 33
            repeat: true
            running: true
            onTriggered: {
             console.log("triggred");
             moving_text.x = moving_text.x-1
             if(moving_text.x<-1*moving_text.paintedWidth)
               moving_text.x=parent.width
            }
        }

        Text{
            id:moving_text
            x:parent.width
            text:"Moving text"
            color: "white"
        }
    }
Run Code Online (Sandbox Code Playgroud)

qt qml

3
推荐指数
1
解决办法
2146
查看次数

标签 统计

qml ×2

qt ×2

android ×1

c++ ×1

maps ×1