If it couldn't find a file then you provided an incorrect URL for it. Using or not using a function doesn't matter here.
Is this something that you wanted to do?
import QtQuick 2.3
import QtQuick.Controls 1.0
Item {
id: root
width: 800
height: 200
property int currentLevel: 0
property int levelUnderMouse: -1
property bool indicatorEnabled: true
property int maxLevel: 10
Button {
checkable: true
checked: true
text: "Enabled"
anchors.left: parent.left
anchors.top: parent.top
onCheckedChanged: indicatorEnabled = checked
}
function urlForState(disabled, hover, active) {
// put your logic here
if(disabled && active) "http://www.qtcentre.org/images/reputation/reputation_highneg.png"
if(disabled) return "http://www.qtcentre.org/images/reputation/reputation_neg.png"
if(active) return "http://www.qtcentre.org/images/reputation/reputation_pos.png"
if(hover) return "http://www.qtcentre.org/images/reputation/reputation_pos.png"
return "http://www.qtcentre.org/images/reputation/reputation_highpos.png"
}
Item {
anchors.centerIn:parent
width: row.width
height: row.height
scale: 4
Row {
id: row
spacing: 2
Repeater {
model: root.maxLevel
Image {
source: root.urlForState(!indicatorEnabled, index === levelUnderMouse, currentLevel >= index)
}
}
}
MouseArea {
anchors.fill: row
hoverEnabled: true
enabled: !root.disabled
function xToIndex(xPos) { return xPos/row.width*root.maxLevel }
onClicked: {
root.currentLevel = xToIndex(mouse.x)
}
onPositionChanged: {
var idx = xToIndex(mouse.x)
root.levelUnderMouse = idx
if(pressed)
root.currentLevel = idx
}
onExited: root.levelUnderMouse = -1
}
}
}
import QtQuick 2.3
import QtQuick.Controls 1.0
Item {
id: root
width: 800
height: 200
property int currentLevel: 0
property int levelUnderMouse: -1
property bool indicatorEnabled: true
property int maxLevel: 10
Button {
checkable: true
checked: true
text: "Enabled"
anchors.left: parent.left
anchors.top: parent.top
onCheckedChanged: indicatorEnabled = checked
}
function urlForState(disabled, hover, active) {
// put your logic here
if(disabled && active) "http://www.qtcentre.org/images/reputation/reputation_highneg.png"
if(disabled) return "http://www.qtcentre.org/images/reputation/reputation_neg.png"
if(active) return "http://www.qtcentre.org/images/reputation/reputation_pos.png"
if(hover) return "http://www.qtcentre.org/images/reputation/reputation_pos.png"
return "http://www.qtcentre.org/images/reputation/reputation_highpos.png"
}
Item {
anchors.centerIn:parent
width: row.width
height: row.height
scale: 4
Row {
id: row
spacing: 2
Repeater {
model: root.maxLevel
Image {
source: root.urlForState(!indicatorEnabled, index === levelUnderMouse, currentLevel >= index)
}
}
}
MouseArea {
anchors.fill: row
hoverEnabled: true
enabled: !root.disabled
function xToIndex(xPos) { return xPos/row.width*root.maxLevel }
onClicked: {
root.currentLevel = xToIndex(mouse.x)
}
onPositionChanged: {
var idx = xToIndex(mouse.x)
root.levelUnderMouse = idx
if(pressed)
root.currentLevel = idx
}
onExited: root.levelUnderMouse = -1
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks