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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#!/usr/bin/env python
#****************************************************************************
#** $Id$
#**
#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved.
#**
#** This file is part of an example program for PyQt. This example
#** program may be used, distributed and modified without limitation.
#**
#*****************************************************************************/
import sys
from qt import *
TRUE = 1
FALSE = 0
class LineEdits(QGroupBox):
def __init__(self, parent = None, name = None):
QGroupBox.__init__(self, 0, Qt.Horizontal, "Line Edits", parent, name)
self.setMargin(10)
box = QVBoxLayout(self.layout())
row1 = QHBoxLayout(box)
row1.setMargin(5)
label = QLabel("Echo Mode: ", self)
row1.addWidget(label)
combo1 = QComboBox(FALSE, self)
row1.addWidget(combo1)
combo1.insertItem("Normal", -1)
combo1.insertItem("Password", -1)
combo1.insertItem("No Echo", -1)
self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged)
self.lined1 = QLineEdit(self)
box.addWidget(self.lined1)
row2 = QHBoxLayout(box)
row2.setMargin(5)
label = QLabel("Validator: ", self)
row2.addWidget(label)
combo2 = QComboBox(FALSE, self)
row2.addWidget(combo2)
combo2.insertItem("No Validator", -1)
combo2.insertItem("Integer Validator", -1)
combo2.insertItem("Double Validator", -1)
self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged)
self.lined2 = QLineEdit(self)
box.addWidget(self.lined2)
row3 = QHBoxLayout(box)
row3.setMargin(5)
label = QLabel("Alignment: ", self)
row3.addWidget(label)
combo3 = QComboBox(FALSE, self)
row3.addWidget(combo3)
combo3.insertItem("Left", -1)
combo3.insertItem("Centered", -1)
combo3.insertItem("Right", -1)
self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged)
self.lined3 = QLineEdit(self)
box.addWidget(self.lined3)
row4 = QHBox(self)
box.addWidget(row4)
row4.setMargin(5)
QLabel("Read-Only: ", row4)
combo4 = QComboBox(FALSE, row4)
combo4.insertItem("False", -1)
combo4.insertItem("True", -1)
self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged)
self.lined4 = QLineEdit(self)
box.addWidget(self.lined4)
self.lined1.setFocus()
def slotEchoChanged(self, i):
if i == 0:
self.lined1.setEchoMode(QLineEdit.Normal)
elif i == 1:
self.lined1.setEchoMode(QLineEdit.Password)
elif i == 2:
self.lined1.setEchoMode(QLineEdit.NoEcho)
self.lined1.setFocus()
def slotValidatorChanged(self, i):
if i == 0:
self.lined2.setValidator(None)
elif i == 1:
self.lined2.setValidator(QIntValidator(self.lined2))
elif i == 2:
self.lined2.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.lined2))
self.lined2.setText("")
self.lined2.setFocus()
def slotAlignmentChanged(self, i):
if i == 0:
self.lined3.setAlignment(QLineEdit.AlignLeft)
elif i == 1:
self.lined3.setAlignment(QLineEdit.AlignCenter)
elif i == 2:
self.lined3.setAlignment(QLineEdit.AlignRight)
self.lined3.setFocus()
def slotReadOnlyChanged(self, i):
if i == 0:
self.lined4.setReadOnly(FALSE)
elif i == 1:
self.lined4.setReadOnly(TRUE)
self.lined4.setFocus()
if __name__=='__main__':
app = QApplication( sys.argv )
lineedits = LineEdits()
lineedits.setCaption("Lineedits - PyQt Example")
lineedits.show()
app.setMainWidget(lineedits)
app.exec_loop()
|