这是我现在的QML:
import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6
Rectangle {
width: 720
height: 480
Plugin {
id: myPlugin
name: "osm"
//specify plugin parameters if necessary
//PluginParameter {...}
//PluginParameter {...}
//...
}
PositionSource {
id: positionSource
property variant lastSearchPosition: locationOslo
active: true
updateInterval: 120000 // 2 mins
onPositionChanged: {
var currentPosition = positionSource.position.coordinate
map.center = currentPosition
var distance = currentPosition.distanceTo(lastSearchPosition)
if (distance > 500) {
// 500m from last performed pizza search
lastSearchPosition = currentPosition
searchModel.searchArea = QtPositioning.circle(currentPosition)
searchModel.update()
}
}
}
property variant locationOslo: QtPositioning.coordinate( 40.42, -86.91 )
PlaceSearchModel {
id: searchModel
plugin: myPlugin
searchTerm: "Pizza"
searchArea: QtPositioning.circle(locationOslo)
Component.onCompleted: update()
}
Map {
id: map
anchors.fill: parent
plugin: myPlugin;
center: locationOslo
zoomLevel: 13
MapItemView {
model: searchModel
delegate: MapQuickItem {
coordinate: place.location.coordinate
anchorPoint.x: image.width * 0.5
anchorPoint.y: image.height
sourceItem: Column {
Image { id: image; source: "marker.png" }
Text { text: title; font.bold: true }
}
}
}
Connections {
target: searchModel
onStatusChanged: {
if (searchModel.status == PlaceSearchModel.Error)
console.log(searchModel.errorString());
}
}
}
}
我希望Rectangle填充我嵌入它的QQuickWidget
。以下是代码:
map_view = QQuickWidget()
map_view.setSource(QUrl('src/map.qml'))
layout.addWidget(map_view)
截至目前,因为我正在对Rectangle对象的宽度,高度进行硬编码,结果如下所示:
如何在QML中指定我希望它填充嵌入的QQuickWidget
?