问题描述
我正在构建一个映射程序,该程序最终希望基于模型中的值在地图上显示其他项目。为方便起见,我在frame[y:y2,x:x2] = rgb_noise_mask[y:y2,x:x2]
代表中使用frame[y:y2,x:x2] = frame[y:y2,x:x2][::-1]
。
不幸的是,当我对此进行测试时,Loader
方法什么也没显示。
MapItemDelegate.qml
MapItemView
main.qml
Loader
如何让MapQuickItem {
id: waypoint
anchorPoint.x: image.width/2
anchorPoint.y: image.height/2
coordinate: task.waypoint //task extends QObject with members taskname and waypoint
sourceItem: Grid: {
columns: 1
rows:2
horizontalItemAlignment: Grid.AlignHCenter
Image {
id: image
source: "Waypoint.png"
height: 32
width: 32
}
Text {
id: text
text: task.taskname
}
}
}
实际显示已加载MapItemView {
id: taskview
model: tasklistmodel //Extends AbstractListModel to contain task objects
delegate: Component {
//Desired method,fails to display.
Loader {
source:"MapItemDelegate.qml"
// Will eventually be:
// source: task.typename+"MapItemDelegate.qml" to facilitate several types.
}
//Control method. Works fine,but does not meet my requirements.
MapItemDelegate {
//nothing further needed.
}
}
}
的{{1}}?是否有另一种动态加载代表以进行显示的方法?
解决方法
事实证明,在Loader
的委托中不能使用MapItemView
,因为API要求Component
包含单个映射对象。 Loader
确实加载了映射对象,但它本身并不是映射对象,这导致该对象无法显示。
我最终要做的是实现一个自定义QSortFilterProxyModel
,该自定义filterAcceptsRow
会覆盖tasklistmodel
以过滤task.typename
以匹配MapItemView
属性,然后将我的MapItemView {
id:taskview
model: TaskListFilterModel { // custom extension of QSortFilterProxyModel
acceptType:"dothisthingtype"
sourceModel: tasklistmodel
}
delegate:MapItemDelegate {
}
}
编辑为如下:
MapItemView
这样,我可以为以后计划添加的每种任务添加一个Loader
。尽管它比我希望Vue.component('ethique-chart',{
extends: VueChartJs.Doughnut,mounted () {
this.renderChart({
labels: [['Lutte contre la corruption','active ou passive'],['Actions en faveur de la responsabilité','sociétale chez les fournisseurs'] ],datasets: [
{
backgroundColor: [ '#0075AA','#258BB7'],data: [90,7]
}
]
},{responsive: true,maintainAspectRatio: false,legend: { display: false},animation: {
duration: 3000,easing : 'easeInOutQuad'
},tooltips: { backgroundColor: 'rgba(231,30,116,.87)',callbacks: {
label: function(tooltipItem,data) {
return data['labels'][tooltipItem['index']] + ': ' + data['datasets'][0]['data'][tooltipItem['index']] + '%';
}
}
}
})
}
})
所实现的优雅和工作方式要少得多,但它至少可以满足我的要求。