-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextFieldExt.qml
65 lines (53 loc) · 1.3 KB
/
TextFieldExt.qml
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import QtQuick 2.0
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
TextField {
property bool autoSelectText: true
property string tooltip: ""
property string label: ""
property int minWidth: 115
property var labelColor
// handle changes internally
property var target: null
property string property: ""
Layout.preferredHeight: 59
Layout.minimumHeight: 59
Layout.minimumWidth: minWidth
Layout.fillWidth: true
verticalAlignment: Text.AlignBottom
// flush changes before writing to device (or closing view)
Connections {
target: window
onBeforeSave: function() {
saveChanges()
}
onBeforeClose: function() {
saveChanges()
}
}
function saveChanges() {
if (target && property) {
target[property] = text
}
}
Label {
text: label
wrapMode: Text.WrapAnywhere
color: labelColor || color
}
ToolTip {
visible: tooltip && parent.hovered
text: tooltip
}
onFocusChanged: {
if (autoSelectText) {
if (focus)
selectAll();
else
deselect();
}
// flush changes when focus lost
if (!focus)
saveChanges()
}
}