aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/snippets/data/qtlabscontrols-spinbox-textual.qml
blob: cdcbc1bc9690730324121d96a1123063a53619a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import QtQuick 2.0
import Qt.labs.controls 1.0

//! [1]
SpinBox {
    from: 0
    to: items.length - 1
    value: 1 // "Medium"

    property var items: ["Small", "Medium", "Large"]

    validator: RegExpValidator {
        regExp: new RegExp("(Small|Medium|Large)", "i")
    }

    textFromValue: function(value) {
        return items[value];
    }

    valueFromText: function(text) {
        for (var i = 0; i < items.length; ++i) {
            if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0)
                return i
        }
        return sb.value
    }
}
//! [1]