-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdittableText.qml
More file actions
77 lines (72 loc) · 1.49 KB
/
EdittableText.qml
File metadata and controls
77 lines (72 loc) · 1.49 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
Item {
id: editableText
property string text
states: [
State {
name: "editMode"
PropertyChanges {target: displayText; visible: false}
PropertyChanges {target: editText; visible: true }
},
State {
name: "displayMode"
PropertyChanges {target: displayText; visible: true}
PropertyChanges {target: editText; visible: false }
}
]
state: "displayMode"
Item {
id: displayText
anchors.fill: parent
Text {
leftPadding: 5
anchors.fill: parent
text: editableText.text
color: "white"
verticalAlignment: Text.AlignVCenter
font {
family: rubikLight.name
pixelSize: 12
}
MouseArea {
enabled: true
anchors.fill: parent
hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
onDoubleClicked: {
editableText.state = "editMode";
}
}
}
}
TextField {
id: editText
anchors.fill: parent
text: editableText.text
placeholderText: "Enter name"
onEditingFinished: {
editableText.state = "displayMode";
if (text !== parent.text) {
parent.text = text;
}
}
onVisibleChanged: {
if (visible) {
this.forceActiveFocus();
}
}
font {
family: rubikLight.name
pixelSize: 12
}
style: TextFieldStyle {
textColor: "black"
background: Rectangle {
color: "white"
anchors.fill: parent
}
}
}
}