0
我是一个beginer和我没有得到如何在我的QML调用canvas.requestPaint()能够canvas.requestPaint(),代码如下:QML - 不是从一个函数
//myTab.qml
TabView {
id: tv
width: parent.width
height: parent.height
antialiasing: true
style: TabViewStyle {
frameOverlap: -1
tab: Rectangle {
color: "Transparent"
implicitWidth: text1.width + 50
implicitHeight: 20
radius: 2
smooth: true
Canvas {
id: canvas1
anchors.fill: parent
width: parent.width
height: parent.height
onPaint: {
styleData.selected ? drawTab(canvas1,"#0C3142") :
drawTab(canvas1,"Transparent") //Some custom JS function to draw a object
}
Text {
id: text1
height: parent.height
verticalAlignment: Text.AlignVCenter
anchors.left : parent.left
anchors.leftMargin: 15
text: styleData.title
color: "white"
}
}
}
frame: Rectangle {
width: parent.width
height: parent.height
color: "Transparent"
border.color:"white"
}
tabBar: Rectangle {
color: "Transparent"
anchors.fill: parent
}
}
Tab {
id: tab1
title: "Tab1"
}
Tab{
id: tab2
title: "Tab2"
}
onCurrentIndexChanged: {
console.log("index changed "+currentIndex)
canvas1.repaint() //ERRROR - not defind canvas1
}
}
当我尝试在onCurrentIndexChanged
使用,我收到以下错误:
ReferenceError: canvas1 is not defined.
请建议。
我添加了一个信号刷新()和后制成的在Canvas中连接,但我得到了“QML连接:不能分配给不存在的属性”onRefresh“”错误。 – pra7
这正是我需要..我使用目标:canvas1,这就是它没有工作的原因....谢谢@derM – pra7