1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
<title>Qt 4.0: window.cpp Example File (widgets/lineedits/window.cpp)</title>
7
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
8
a:link { color: #004faf; text-decoration: none }
9
a:visited { color: #672967; text-decoration: none }
10
td.postheader { font-family: sans-serif }
11
tr.address { font-family: sans-serif }
12
body { background: #ffffff; color: black; }</style>
15
<table border="0" cellpadding="0" cellspacing="0" width="100%">
17
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
18
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="annotated.html"><font color="#004faf">Annotated</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
19
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">window.cpp Example File<br /><small><small>widgets/lineedits/window.cpp</small></small></h1>
20
<pre> /****************************************************************************
22
** Copyright (C) 2004-2005 Trolltech AS. All rights reserved.
24
** This file is part of the documentation of the Qt Toolkit.
26
** This file may be distributed under the terms of the Q Public License
27
** as defined by Trolltech AS of Norway and appearing in the file
28
** LICENSE.QPL included in the packaging of this file.
30
** This file may be distributed and/or modified under the terms of the
31
** GNU General Public License version 2 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file.
35
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
36
** information about Qt Commercial License Agreements.
37
** See http://www.trolltech.com/qpl/ for QPL licensing information.
38
** See http://www.trolltech.com/gpl/ for GPL licensing information.
40
** Contact info@trolltech.com if any conditions of this licensing are
43
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
44
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46
****************************************************************************/
48
#include <QtGui>
50
#include "window.h"
54
QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
56
QLabel *echoLabel = new QLabel(tr("Mode:"));
57
QComboBox *echoComboBox = new QComboBox;
58
echoComboBox->addItem(tr("Normal"));
59
echoComboBox->addItem(tr("Password"));
60
echoComboBox->addItem(tr("No Echo"));
62
echoLineEdit = new QLineEdit;
63
echoLineEdit->setFocus();
65
QGroupBox *validatorGroup = new QGroupBox(tr("Validator"));
67
QLabel *validatorLabel = new QLabel(tr("Type:"));
68
QComboBox *validatorComboBox = new QComboBox;
69
validatorComboBox->addItem(tr("No validator"));
70
validatorComboBox->addItem(tr("Integer validator"));
71
validatorComboBox->addItem(tr("Double validator"));
73
validatorLineEdit = new QLineEdit;
75
QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment"));
77
QLabel *alignmentLabel = new QLabel(tr("Type:"));
78
QComboBox *alignmentComboBox = new QComboBox;
79
alignmentComboBox->addItem(tr("Left"));
80
alignmentComboBox->addItem(tr("Centered"));
81
alignmentComboBox->addItem(tr("Right"));
83
alignmentLineEdit = new QLineEdit;
85
QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask"));
87
QLabel *inputMaskLabel = new QLabel(tr("Type:"));
88
QComboBox *inputMaskComboBox = new QComboBox;
89
inputMaskComboBox->addItem(tr("No mask"));
90
inputMaskComboBox->addItem(tr("Phone number"));
91
inputMaskComboBox->addItem(tr("ISO date"));
92
inputMaskComboBox->addItem(tr("License key"));
94
inputMaskLineEdit = new QLineEdit;
96
QGroupBox *accessGroup = new QGroupBox(tr("Access"));
98
QLabel *accessLabel = new QLabel(tr("Read-only:"));
99
QComboBox *accessComboBox = new QComboBox;
100
accessComboBox->addItem(tr("False"));
101
accessComboBox->addItem(tr("True"));
103
accessLineEdit = new QLineEdit;
105
connect(echoComboBox, SIGNAL(activated(int)),
106
this, SLOT(slotEchoChanged(int)));
107
connect(validatorComboBox, SIGNAL(activated(int)),
108
this, SLOT(slotValidatorChanged(int)));
109
connect(alignmentComboBox, SIGNAL(activated(int)),
110
this, SLOT(slotAlignmentChanged(int)));
111
connect(inputMaskComboBox, SIGNAL(activated(int)),
112
this, SLOT(slotInputMaskChanged(int)));
113
connect(accessComboBox, SIGNAL(activated(int)),
114
this, SLOT(slotAccessChanged(int)));
116
QGridLayout *echoLayout = new QGridLayout;
117
echoLayout->addWidget(echoLabel, 0, 0);
118
echoLayout->addWidget(echoComboBox, 0, 1);
119
echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2);
120
echoGroup->setLayout(echoLayout);
122
QGridLayout *validatorLayout = new QGridLayout;
123
validatorLayout->addWidget(validatorLabel, 0, 0);
124
validatorLayout->addWidget(validatorComboBox, 0, 1);
125
validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2);
126
validatorGroup->setLayout(validatorLayout);
128
QGridLayout *alignmentLayout = new QGridLayout;
129
alignmentLayout->addWidget(alignmentLabel, 0, 0);
130
alignmentLayout->addWidget(alignmentComboBox, 0, 1);
131
alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2);
132
alignmentGroup-> setLayout(alignmentLayout);
134
QGridLayout *inputMaskLayout = new QGridLayout;
135
inputMaskLayout->addWidget(inputMaskLabel, 0, 0);
136
inputMaskLayout->addWidget(inputMaskComboBox, 0, 1);
137
inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2);
138
inputMaskGroup->setLayout(inputMaskLayout);
140
QGridLayout *accessLayout = new QGridLayout;
141
accessLayout->addWidget(accessLabel, 0, 0);
142
accessLayout->addWidget(accessComboBox, 0, 1);
143
accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2);
144
accessGroup->setLayout(accessLayout);
146
QVBoxLayout *layout = new QVBoxLayout;
147
layout->addWidget(echoGroup);
148
layout->addWidget(validatorGroup);
149
layout->addWidget(alignmentGroup);
150
layout->addWidget(inputMaskGroup);
151
layout->addWidget(accessGroup);
154
setWindowTitle(tr("Line Edits"));
157
void Window::slotEchoChanged(int index)
161
echoLineEdit->setEchoMode(QLineEdit::Normal);
164
echoLineEdit->setEchoMode(QLineEdit::Password);
167
echoLineEdit->setEchoMode(QLineEdit::NoEcho);
172
void Window::slotValidatorChanged(int index)
176
validatorLineEdit->setValidator(0);
179
validatorLineEdit->setValidator(new QIntValidator(
183
validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
184
999.0, 2, validatorLineEdit));
188
validatorLineEdit->setText("");
191
void Window::slotAlignmentChanged(int index)
195
alignmentLineEdit->setAlignment(Qt::AlignLeft);
198
alignmentLineEdit->setAlignment(Qt::AlignCenter);
201
alignmentLineEdit->setAlignment(Qt::AlignRight);
206
void Window::slotInputMaskChanged(int index)
210
inputMaskLineEdit->setInputMask(QString());
213
inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
216
inputMaskLineEdit->setInputMask("0000-00-00");
217
inputMaskLineEdit->setText("00000000");
218
inputMaskLineEdit->setCursorPosition(0);
221
inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
226
void Window::slotAccessChanged(int index)
230
accessLineEdit->setReadOnly(false);
233
accessLineEdit->setReadOnly(true);
237
<p /><address><hr /><div align="center">
238
<table width="100%" cellspacing="0" border="0"><tr class="address">
239
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
240
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
241
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
242
</tr></table></div></address></body>