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