1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtGui module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include "qinputdialog.h"
44
#ifndef QT_NO_INPUTDIALOG
46
#include "qapplication.h"
47
#include "qcombobox.h"
48
#include "qdialogbuttonbox.h"
51
#include "qlineedit.h"
52
#include "qlistwidget.h"
53
#include "qpushbutton.h"
55
#include "qstackedlayout.h"
56
#include "qvalidator.h"
58
#include "qdialog_p.h"
62
static const char *signalForMember(const char *member)
64
static const int NumCandidates = 4;
65
static const char * const candidateSignals[NumCandidates] = {
66
SIGNAL(textValueSelected(QString)),
67
SIGNAL(intValueSelected(int)),
68
SIGNAL(doubleValueSelected(double)),
72
QByteArray normalizedMember(QMetaObject::normalizedSignature(member));
75
while (i < NumCandidates - 1) { // sic
76
if (QMetaObject::checkConnectArgs(candidateSignals[i], normalizedMember))
80
return candidateSignals[i];
86
These internal classes add extra validation to QSpinBox and QDoubleSpinBox by emitting
87
textChanged(bool) after events that may potentially change the visible text. Return or
88
Enter key presses are not propagated if the visible text is invalid. Instead, the visible
89
text is modified to the last valid value.
91
class QInputDialogSpinBox : public QSpinBox
96
QInputDialogSpinBox(QWidget *parent)
98
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
99
connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
103
void textChanged(bool);
106
void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
109
void keyPressEvent(QKeyEvent *event) {
110
if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
111
#ifndef QT_NO_PROPERTIES
112
setProperty("value", property("value"));
115
QSpinBox::keyPressEvent(event);
120
void mousePressEvent(QMouseEvent *event) {
121
QSpinBox::mousePressEvent(event);
126
class QInputDialogDoubleSpinBox : public QDoubleSpinBox
131
QInputDialogDoubleSpinBox(QWidget *parent = 0)
132
: QDoubleSpinBox(parent) {
133
connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
134
connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
138
void textChanged(bool);
141
void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
144
void keyPressEvent(QKeyEvent *event) {
145
if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
146
#ifndef QT_NO_PROPERTIES
147
setProperty("value", property("value"));
150
QDoubleSpinBox::keyPressEvent(event);
155
void mousePressEvent(QMouseEvent *event) {
156
QDoubleSpinBox::mousePressEvent(event);
161
class QInputDialogPrivate : public QDialogPrivate
163
Q_DECLARE_PUBLIC(QInputDialog)
166
QInputDialogPrivate();
169
void ensureLineEdit();
170
void ensureComboBox();
171
void ensureListView();
172
void ensureIntSpinBox();
173
void ensureDoubleSpinBox();
174
void ensureEnabledConnection(QAbstractSpinBox *spinBox);
175
void setInputWidget(QWidget *widget);
176
void chooseRightTextInputWidget();
177
void setComboBoxText(const QString &text);
178
void setListViewText(const QString &text);
179
QString listViewText() const;
180
void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); }
181
bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; }
182
void _q_textChanged(const QString &text);
183
void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex);
185
mutable QLabel *label;
186
mutable QDialogButtonBox *buttonBox;
187
mutable QLineEdit *lineEdit;
188
mutable QSpinBox *intSpinBox;
189
mutable QDoubleSpinBox *doubleSpinBox;
190
mutable QComboBox *comboBox;
191
mutable QListView *listView;
192
mutable QWidget *inputWidget;
193
mutable QVBoxLayout *mainLayout;
194
QInputDialog::InputDialogOptions opts;
196
QPointer<QObject> receiverToDisconnectOnClose;
197
QByteArray memberToDisconnectOnClose;
200
QInputDialogPrivate::QInputDialogPrivate()
201
: label(0), buttonBox(0), lineEdit(0), intSpinBox(0), doubleSpinBox(0), comboBox(0), listView(0),
202
inputWidget(0), mainLayout(0)
206
void QInputDialogPrivate::ensureLayout()
215
inputWidget = lineEdit;
219
label = new QLabel(QInputDialog::tr("Enter a value:"), q);
220
#ifndef QT_NO_SHORTCUT
221
label->setBuddy(inputWidget);
223
label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
225
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
226
QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
227
QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
229
mainLayout = new QVBoxLayout(q);
230
//we want to let the input dialog grow to available size on Symbian.
231
mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
232
mainLayout->addWidget(label);
233
mainLayout->addWidget(inputWidget);
234
mainLayout->addWidget(buttonBox);
235
ensureEnabledConnection(qobject_cast<QAbstractSpinBox *>(inputWidget));
239
void QInputDialogPrivate::ensureLineEdit()
243
lineEdit = new QLineEdit(q);
245
qt_widget_private(lineEdit)->inheritsInputMethodHints = 1;
248
QObject::connect(lineEdit, SIGNAL(textChanged(QString)),
249
q, SLOT(_q_textChanged(QString)));
253
void QInputDialogPrivate::ensureComboBox()
257
comboBox = new QComboBox(q);
259
qt_widget_private(comboBox)->inheritsInputMethodHints = 1;
262
QObject::connect(comboBox, SIGNAL(editTextChanged(QString)),
263
q, SLOT(_q_textChanged(QString)));
264
QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)),
265
q, SLOT(_q_textChanged(QString)));
269
void QInputDialogPrivate::ensureListView()
275
listView = new QListView(q);
277
listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
278
listView->setSelectionMode(QAbstractItemView::SingleSelection);
279
listView->setModel(comboBox->model());
280
listView->setCurrentIndex(QModelIndex()); // ###
281
QObject::connect(listView->selectionModel(),
282
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
283
q, SLOT(_q_currentRowChanged(QModelIndex,QModelIndex)));
287
void QInputDialogPrivate::ensureIntSpinBox()
291
intSpinBox = new QInputDialogSpinBox(q);
293
QObject::connect(intSpinBox, SIGNAL(valueChanged(int)),
294
q, SIGNAL(intValueChanged(int)));
298
void QInputDialogPrivate::ensureDoubleSpinBox()
301
if (!doubleSpinBox) {
302
doubleSpinBox = new QInputDialogDoubleSpinBox(q);
303
doubleSpinBox->hide();
304
QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)),
305
q, SIGNAL(doubleValueChanged(double)));
309
void QInputDialogPrivate::ensureEnabledConnection(QAbstractSpinBox *spinBox)
312
QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
313
QObject::connect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)), Qt::UniqueConnection);
317
void QInputDialogPrivate::setInputWidget(QWidget *widget)
320
if (inputWidget == widget)
324
Q_ASSERT(inputWidget);
325
mainLayout->removeWidget(inputWidget);
327
mainLayout->insertWidget(1, widget);
330
// disconnect old input widget
331
QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
332
if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(inputWidget))
333
QObject::disconnect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)));
335
// connect new input widget and update enabled state of OK button
336
QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(widget);
337
ensureEnabledConnection(spinBox);
338
okButton->setEnabled(!spinBox || spinBox->hasAcceptableInput());
341
inputWidget = widget;
343
// synchronize the text shown in the new text editor with the current
345
if (widget == lineEdit) {
346
lineEdit->setText(textValue);
347
} else if (widget == comboBox) {
348
setComboBoxText(textValue);
349
} else if (widget == listView) {
350
setListViewText(textValue);
352
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(listView->selectionModel()->hasSelection());
356
void QInputDialogPrivate::chooseRightTextInputWidget()
360
if (useComboBoxOrListView()) {
361
if ((opts & QInputDialog::UseListViewForComboBoxItems) && !comboBox->isEditable()) {
372
setInputWidget(widget);
374
if (inputWidget == comboBox) {
375
_q_textChanged(comboBox->currentText());
376
} else if (inputWidget == listView) {
377
_q_textChanged(listViewText());
381
void QInputDialogPrivate::setComboBoxText(const QString &text)
383
int index = comboBox->findText(text);
385
comboBox->setCurrentIndex(index);
386
} else if (comboBox->isEditable()) {
387
comboBox->setEditText(text);
391
void QInputDialogPrivate::setListViewText(const QString &text)
393
int row = comboBox->findText(text);
395
QModelIndex index(comboBox->model()->index(row, 0));
396
listView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Clear
397
| QItemSelectionModel::SelectCurrent);
401
QString QInputDialogPrivate::listViewText() const
403
if (listView->selectionModel()->hasSelection()) {
404
int row = listView->selectionModel()->selectedRows().value(0).row();
405
return comboBox->itemText(row);
411
void QInputDialogPrivate::_q_textChanged(const QString &text)
414
if (textValue != text) {
416
emit q->textValueChanged(text);
420
void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex,
421
const QModelIndex & /* oldIndex */)
423
_q_textChanged(comboBox->model()->data(newIndex).toString());
424
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
429
\brief The QInputDialog class provides a simple convenience dialog to get a
430
single value from the user.
431
\ingroup standard-dialogs
434
The input value can be a string, a number or an item from a list. A label
435
must be set to tell the user what they should enter.
437
Four static convenience functions are provided: getText(), getInt(),
438
getDouble(), and getItem(). All the functions can be used in a similar way,
441
\snippet dialogs/standarddialogs/dialog.cpp 3
443
The \c ok variable is set to true if the user clicks \uicontrol OK; otherwise it
446
\image inputdialogs.png Input Dialogs
448
The \l{dialogs/standarddialogs}{Standard Dialogs} example shows how to use
449
QInputDialog as well as other built-in Qt dialogs.
451
\sa QMessageBox, {Standard Dialogs Example}
455
\enum QInputDialog::InputMode
458
This enum describes the different modes of input that can be selected for
461
\value TextInput Used to input text strings.
462
\value IntInput Used to input integers.
463
\value DoubleInput Used to input floating point numbers with double
472
Constructs a new input dialog with the given \a parent and window \a flags.
474
QInputDialog::QInputDialog(QWidget *parent, Qt::WindowFlags flags)
475
: QDialog(*new QInputDialogPrivate, parent, flags)
482
Destroys the input dialog.
484
QInputDialog::~QInputDialog()
491
\property QInputDialog::inputMode
493
\brief the mode used for input
495
This property help determines which widget is used for entering input into
498
void QInputDialog::setInputMode(InputMode mode)
505
Warning: Some functions in QInputDialog rely on implementation details
506
of the code below. Look for the comments that accompany the calls to
507
setInputMode() throughout this file before you change the code below.
512
d->ensureIntSpinBox();
513
widget = d->intSpinBox;
516
d->ensureDoubleSpinBox();
517
widget = d->doubleSpinBox;
520
Q_ASSERT(mode == TextInput);
521
d->chooseRightTextInputWidget();
525
d->setInputWidget(widget);
528
QInputDialog::InputMode QInputDialog::inputMode() const
530
Q_D(const QInputDialog);
532
if (d->inputWidget) {
533
if (d->inputWidget == d->intSpinBox) {
535
} else if (d->inputWidget == d->doubleSpinBox) {
546
\property QInputDialog::labelText
548
\brief the text to for the label to describe what needs to be input
550
void QInputDialog::setLabelText(const QString &text)
554
d->label = new QLabel(text, this);
556
d->label->setText(text);
560
QString QInputDialog::labelText() const
562
Q_D(const QInputDialog);
564
return d->label->text();
568
\enum QInputDialog::InputDialogOption
572
This enum specifies various options that affect the look and feel
575
\value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
576
\value UseListViewForComboBoxItems Use a QListView rather than a non-editable QComboBox for
577
displaying the items set with setComboBoxItems().
579
\sa options, setOption(), testOption()
583
Sets the given \a option to be enabled if \a on is true;
584
otherwise, clears the given \a option.
586
\sa options, testOption()
588
void QInputDialog::setOption(InputDialogOption option, bool on)
591
if (!(d->opts & option) != !on)
592
setOptions(d->opts ^ option);
596
Returns true if the given \a option is enabled; otherwise, returns
599
\sa options, setOption()
601
bool QInputDialog::testOption(InputDialogOption option) const
603
Q_D(const QInputDialog);
604
return (d->opts & option) != 0;
608
\property QInputDialog::options
609
\brief the various options that affect the look and feel of the dialog
612
By default, all options are disabled.
614
\sa setOption(), testOption()
616
void QInputDialog::setOptions(InputDialogOptions options)
620
InputDialogOptions changed = (options ^ d->opts);
627
if (changed & NoButtons)
628
d->buttonBox->setVisible(!(options & NoButtons));
629
if ((changed & UseListViewForComboBoxItems) && inputMode() == TextInput)
630
d->chooseRightTextInputWidget();
633
QInputDialog::InputDialogOptions QInputDialog::options() const
635
Q_D(const QInputDialog);
642
\property QInputDialog::textValue
644
\brief the text value for the input dialog
646
This property is only relevant when the input dialog is used in
649
void QInputDialog::setTextValue(const QString &text)
653
setInputMode(TextInput);
654
if (d->inputWidget == d->lineEdit) {
655
d->lineEdit->setText(text);
656
} else if (d->inputWidget == d->comboBox) {
657
d->setComboBoxText(text);
659
d->setListViewText(text);
663
QString QInputDialog::textValue() const
665
Q_D(const QInputDialog);
672
\property QInputDialog::textEchoMode
674
\brief the echo mode for the text value
676
This property is only relevant when the input dialog is used in
679
void QInputDialog::setTextEchoMode(QLineEdit::EchoMode mode)
683
d->lineEdit->setEchoMode(mode);
686
QLineEdit::EchoMode QInputDialog::textEchoMode() const
688
Q_D(const QInputDialog);
690
return d->lineEdit->echoMode();
692
return QLineEdit::Normal;
699
\property QInputDialog::comboBoxEditable
701
\brief whether or not the combo box is used in the input dialog is editable
703
void QInputDialog::setComboBoxEditable(bool editable)
707
d->comboBox->setEditable(editable);
708
if (inputMode() == TextInput)
709
d->chooseRightTextInputWidget();
712
bool QInputDialog::isComboBoxEditable() const
714
Q_D(const QInputDialog);
716
return d->comboBox->isEditable();
725
\property QInputDialog::comboBoxItems
727
\brief the items used in the combobox for the input dialog
729
void QInputDialog::setComboBoxItems(const QStringList &items)
734
d->comboBox->blockSignals(true);
735
d->comboBox->clear();
736
d->comboBox->addItems(items);
737
d->comboBox->blockSignals(false);
739
if (inputMode() == TextInput)
740
d->chooseRightTextInputWidget();
743
QStringList QInputDialog::comboBoxItems() const
745
Q_D(const QInputDialog);
748
const int count = d->comboBox->count();
749
for (int i = 0; i < count; ++i)
750
result.append(d->comboBox->itemText(i));
756
\property QInputDialog::intValue
758
\brief the current integer value accepted as input
760
This property is only relevant when the input dialog is used in
763
void QInputDialog::setIntValue(int value)
766
setInputMode(IntInput);
767
d->intSpinBox->setValue(value);
770
int QInputDialog::intValue() const
772
Q_D(const QInputDialog);
774
return d->intSpinBox->value();
781
\property QInputDialog::intMinimum
783
\brief the minimum integer value accepted as input
785
This property is only relevant when the input dialog is used in
788
void QInputDialog::setIntMinimum(int min)
791
d->ensureIntSpinBox();
792
d->intSpinBox->setMinimum(min);
795
int QInputDialog::intMinimum() const
797
Q_D(const QInputDialog);
799
return d->intSpinBox->minimum();
806
\property QInputDialog::intMaximum
808
\brief the maximum integer value accepted as input
810
This property is only relevant when the input dialog is used in
813
void QInputDialog::setIntMaximum(int max)
816
d->ensureIntSpinBox();
817
d->intSpinBox->setMaximum(max);
820
int QInputDialog::intMaximum() const
822
Q_D(const QInputDialog);
824
return d->intSpinBox->maximum();
831
Sets the range of integer values accepted by the dialog when used in
832
IntInput mode, with minimum and maximum values specified by \a min and
835
void QInputDialog::setIntRange(int min, int max)
838
d->ensureIntSpinBox();
839
d->intSpinBox->setRange(min, max);
843
\property QInputDialog::intStep
845
\brief the step by which the integer value is increased and decreased
847
This property is only relevant when the input dialog is used in
850
void QInputDialog::setIntStep(int step)
853
d->ensureIntSpinBox();
854
d->intSpinBox->setSingleStep(step);
857
int QInputDialog::intStep() const
859
Q_D(const QInputDialog);
861
return d->intSpinBox->singleStep();
868
\property QInputDialog::doubleValue
870
\brief the current double precision floating point value accepted as input
872
This property is only relevant when the input dialog is used in
875
void QInputDialog::setDoubleValue(double value)
878
setInputMode(DoubleInput);
879
d->doubleSpinBox->setValue(value);
882
double QInputDialog::doubleValue() const
884
Q_D(const QInputDialog);
885
if (d->doubleSpinBox) {
886
return d->doubleSpinBox->value();
893
\property QInputDialog::doubleMinimum
895
\brief the minimum double precision floating point value accepted as input
897
This property is only relevant when the input dialog is used in
900
void QInputDialog::setDoubleMinimum(double min)
903
d->ensureDoubleSpinBox();
904
d->doubleSpinBox->setMinimum(min);
907
double QInputDialog::doubleMinimum() const
909
Q_D(const QInputDialog);
910
if (d->doubleSpinBox) {
911
return d->doubleSpinBox->minimum();
918
\property QInputDialog::doubleMaximum
920
\brief the maximum double precision floating point value accepted as input
922
This property is only relevant when the input dialog is used in
925
void QInputDialog::setDoubleMaximum(double max)
928
d->ensureDoubleSpinBox();
929
d->doubleSpinBox->setMaximum(max);
932
double QInputDialog::doubleMaximum() const
934
Q_D(const QInputDialog);
935
if (d->doubleSpinBox) {
936
return d->doubleSpinBox->maximum();
943
Sets the range of double precision floating point values accepted by the
944
dialog when used in DoubleInput mode, with minimum and maximum values
945
specified by \a min and \a max respectively.
947
void QInputDialog::setDoubleRange(double min, double max)
950
d->ensureDoubleSpinBox();
951
d->doubleSpinBox->setRange(min, max);
957
\property QInputDialog::doubleDecimals
959
\brief sets the percision of the double spinbox in decimals
961
\sa QDoubleSpinBox::setDecimals()
963
void QInputDialog::setDoubleDecimals(int decimals)
966
d->ensureDoubleSpinBox();
967
d->doubleSpinBox->setDecimals(decimals);
970
int QInputDialog::doubleDecimals() const
972
Q_D(const QInputDialog);
973
if (d->doubleSpinBox) {
974
return d->doubleSpinBox->decimals();
983
\property QInputDialog::okButtonText
985
\brief the text for the button used to accept the entry in the dialog
987
void QInputDialog::setOkButtonText(const QString &text)
989
Q_D(const QInputDialog);
991
d->buttonBox->button(QDialogButtonBox::Ok)->setText(text);
994
QString QInputDialog::okButtonText() const
996
Q_D(const QInputDialog);
998
return d->buttonBox->button(QDialogButtonBox::Ok)->text();
1004
\property QInputDialog::cancelButtonText
1005
\brief the text for the button used to cancel the dialog
1007
void QInputDialog::setCancelButtonText(const QString &text)
1009
Q_D(const QInputDialog);
1011
d->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
1014
QString QInputDialog::cancelButtonText() const
1016
Q_D(const QInputDialog);
1018
return d->buttonBox->button(QDialogButtonBox::Cancel)->text();
1025
This function connects one of its signals to the slot specified by \a receiver
1026
and \a member. The specific signal depends on the arguments that are specified
1027
in \a member. These are:
1030
\li textValueSelected() if \a member has a QString for its first argument.
1031
\li intValueSelected() if \a member has an int for its first argument.
1032
\li doubleValueSelected() if \a member has a double for its first argument.
1033
\li accepted() if \a member has NO arguments.
1036
The signal will be disconnected from the slot when the dialog is closed.
1038
void QInputDialog::open(QObject *receiver, const char *member)
1041
connect(this, signalForMember(member), receiver, member);
1042
d->receiverToDisconnectOnClose = receiver;
1043
d->memberToDisconnectOnClose = member;
1050
QSize QInputDialog::minimumSizeHint() const
1052
Q_D(const QInputDialog);
1054
return QDialog::minimumSizeHint();
1060
QSize QInputDialog::sizeHint() const
1062
Q_D(const QInputDialog);
1064
return QDialog::sizeHint();
1070
void QInputDialog::setVisible(bool visible)
1072
Q_D(const QInputDialog);
1075
d->inputWidget->setFocus();
1076
if (d->inputWidget == d->lineEdit) {
1077
d->lineEdit->selectAll();
1078
} else if (d->inputWidget == d->intSpinBox) {
1079
d->intSpinBox->selectAll();
1080
} else if (d->inputWidget == d->doubleSpinBox) {
1081
d->doubleSpinBox->selectAll();
1084
QDialog::setVisible(visible);
1088
Closes the dialog and sets its result code to \a result. If this dialog
1089
is shown with exec(), done() causes the local event loop to finish,
1090
and exec() to return \a result.
1094
void QInputDialog::done(int result)
1097
QDialog::done(result);
1099
InputMode mode = inputMode();
1102
emit doubleValueSelected(doubleValue());
1105
emit intValueSelected(intValue());
1108
Q_ASSERT(mode == TextInput);
1109
emit textValueSelected(textValue());
1112
if (d->receiverToDisconnectOnClose) {
1113
disconnect(this, signalForMember(d->memberToDisconnectOnClose),
1114
d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
1115
d->receiverToDisconnectOnClose = 0;
1117
d->memberToDisconnectOnClose.clear();
1121
Static convenience function to get a string from the user.
1123
\a title is the text which is displayed in the title bar of the dialog.
1124
\a label is the text which is shown to the user (it should say what should
1126
\a text is the default text which is placed in the line edit.
1127
\a mode is the echo mode the line edit will use.
1128
\a inputMethodHints is the input method hints that will be used in the
1129
edit widget if an input method is active.
1131
If \a ok is nonnull \e *\a ok will be set to true if the user pressed
1132
\uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
1133
is \a parent. The dialog will be modal and uses the specified widget
1136
If the dialog is accepted, this function returns the text in the dialog's
1137
line edit. If the dialog is rejected, a null QString is returned.
1139
Use this static function like this:
1141
\snippet dialogs/standarddialogs/dialog.cpp 3
1143
\warning Do not delete \a parent during the execution of the dialog. If you
1144
want to do this, you should create the dialog yourself using one of the
1145
QInputDialog constructors.
1147
\sa getInt(), getDouble(), getItem()
1150
QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label,
1151
QLineEdit::EchoMode mode, const QString &text, bool *ok,
1152
Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1154
QInputDialog dialog(parent, flags);
1155
dialog.setWindowTitle(title);
1156
dialog.setLabelText(label);
1157
dialog.setTextValue(text);
1158
dialog.setTextEchoMode(mode);
1159
dialog.setInputMethodHints(inputMethodHints);
1161
int ret = dialog.exec();
1165
return dialog.textValue();
1174
Static convenience function to get an integer input from the user.
1176
\a title is the text which is displayed in the title bar of the dialog.
1177
\a label is the text which is shown to the user (it should say what should
1179
\a value is the default integer which the spinbox will be set to.
1180
\a min and \a max are the minimum and maximum values the user may choose.
1181
\a step is the amount by which the values change as the user presses the
1182
arrow buttons to increment or decrement the value.
1184
If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK
1185
and to false if the user pressed \uicontrol Cancel. The dialog's parent is
1186
\a parent. The dialog will be modal and uses the widget \a flags.
1188
On success, this function returns the integer which has been entered by the
1189
user; on failure, it returns the initial \a value.
1191
Use this static function like this:
1193
\snippet dialogs/standarddialogs/dialog.cpp 0
1195
\warning Do not delete \a parent during the execution of the dialog. If you
1196
want to do this, you should create the dialog yourself using one of the
1197
QInputDialog constructors.
1199
\sa getText(), getDouble(), getItem()
1202
int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &label, int value,
1203
int min, int max, int step, bool *ok, Qt::WindowFlags flags)
1205
QInputDialog dialog(parent, flags);
1206
dialog.setWindowTitle(title);
1207
dialog.setLabelText(label);
1208
dialog.setIntRange(min, max);
1209
dialog.setIntValue(value);
1210
dialog.setIntStep(step);
1212
int ret = dialog.exec();
1216
return dialog.intValue();
1223
\fn QInputDialog::getInteger(QWidget *parent, const QString &title, const QString &label, int value, int min, int max, int step, bool *ok, Qt::WindowFlags flags)
1224
\deprecated use getInt()
1226
Static convenience function to get an integer input from the user.
1228
\a title is the text which is displayed in the title bar of the dialog.
1229
\a label is the text which is shown to the user (it should say what should
1231
\a value is the default integer which the spinbox will be set to.
1232
\a min and \a max are the minimum and maximum values the user may choose.
1233
\a step is the amount by which the values change as the user presses the
1234
arrow buttons to increment or decrement the value.
1236
If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK
1237
and to false if the user pressed \uicontrol Cancel. The dialog's parent is
1238
\a parent. The dialog will be modal and uses the widget \a flags.
1240
On success, this function returns the integer which has been entered by the
1241
user; on failure, it returns the initial \a value.
1243
Use this static function like this:
1245
\snippet dialogs/standarddialogs/dialog.cpp 0
1247
\warning Do not delete \a parent during the execution of the dialog. If you
1248
want to do this, you should create the dialog yourself using one of the
1249
QInputDialog constructors.
1251
\sa getText(), getDouble(), getItem()
1255
Static convenience function to get a floating point number from the user.
1257
\a title is the text which is displayed in the title bar of the dialog.
1258
\a label is the text which is shown to the user (it should say what should
1260
\a value is the default floating point number that the line edit will be
1262
\a min and \a max are the minimum and maximum values the user may choose.
1263
\a decimals is the maximum number of decimal places the number may have.
1265
If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK
1266
and to false if the user pressed \uicontrol Cancel. The dialog's parent is
1267
\a parent. The dialog will be modal and uses the widget \a flags.
1269
This function returns the floating point number which has been entered by
1272
Use this static function like this:
1274
\snippet dialogs/standarddialogs/dialog.cpp 1
1276
\warning Do not delete \a parent during the execution of the dialog. If you
1277
want to do this, you should create the dialog yourself using one of the
1278
QInputDialog constructors.
1280
\sa getText(), getInt(), getItem()
1283
double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label,
1284
double value, double min, double max, int decimals, bool *ok,
1285
Qt::WindowFlags flags)
1287
QInputDialog dialog(parent, flags);
1288
dialog.setWindowTitle(title);
1289
dialog.setLabelText(label);
1290
dialog.setDoubleDecimals(decimals);
1291
dialog.setDoubleRange(min, max);
1292
dialog.setDoubleValue(value);
1294
int ret = dialog.exec();
1298
return dialog.doubleValue();
1305
Static convenience function to let the user select an item from a string
1308
\a title is the text which is displayed in the title bar of the dialog.
1309
\a label is the text which is shown to the user (it should say what should
1311
\a items is the string list which is inserted into the combobox.
1312
\a current is the number of the item which should be the current item.
1313
\a inputMethodHints is the input method hints that will be used if the
1314
combobox is editable and an input method is active.
1316
If \a editable is true the user can enter their own text; otherwise the
1317
user may only select one of the existing items.
1319
If \a ok is nonnull \e *\a ok will be set to true if the user pressed
1320
\uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
1321
is \a parent. The dialog will be modal and uses the widget \a flags.
1323
This function returns the text of the current item, or if \a editable is
1324
true, the current text of the combobox.
1326
Use this static function like this:
1328
\snippet dialogs/standarddialogs/dialog.cpp 2
1330
\warning Do not delete \a parent during the execution of the dialog. If you
1331
want to do this, you should create the dialog yourself using one of the
1332
QInputDialog constructors.
1334
\sa getText(), getInt(), getDouble()
1337
QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label,
1338
const QStringList &items, int current, bool editable, bool *ok,
1339
Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1341
QString text(items.value(current));
1343
QInputDialog dialog(parent, flags);
1344
dialog.setWindowTitle(title);
1345
dialog.setLabelText(label);
1346
dialog.setComboBoxItems(items);
1347
dialog.setTextValue(text);
1348
dialog.setComboBoxEditable(editable);
1349
dialog.setInputMethodHints(inputMethodHints);
1351
int ret = dialog.exec();
1355
return dialog.textValue();
1362
\fn void QInputDialog::doubleValueChanged(double value)
1364
This signal is emitted whenever the double value changes in the dialog.
1365
The current value is specified by \a value.
1367
This signal is only relevant when the input dialog is used in
1372
\fn void QInputDialog::doubleValueSelected(double value)
1374
This signal is emitted whenever the user selects a double value by
1375
accepting the dialog; for example, by clicking the \uicontrol{OK} button.
1376
The selected value is specified by \a value.
1378
This signal is only relevant when the input dialog is used in
1383
\fn void QInputDialog::intValueChanged(int value)
1385
This signal is emitted whenever the integer value changes in the dialog.
1386
The current value is specified by \a value.
1388
This signal is only relevant when the input dialog is used in
1393
\fn void QInputDialog::intValueSelected(int value)
1395
This signal is emitted whenever the user selects a integer value by
1396
accepting the dialog; for example, by clicking the \uicontrol{OK} button.
1397
The selected value is specified by \a value.
1399
This signal is only relevant when the input dialog is used in
1404
\fn void QInputDialog::textValueChanged(const QString &text)
1406
This signal is emitted whenever the text string changes in the dialog.
1407
The current string is specified by \a text.
1409
This signal is only relevant when the input dialog is used in
1414
\fn void QInputDialog::textValueSelected(const QString &text)
1416
This signal is emitted whenever the user selects a text string by
1417
accepting the dialog; for example, by clicking the \uicontrol{OK} button.
1418
The selected string is specified by \a text.
1420
This signal is only relevant when the input dialog is used in
1426
#include "qinputdialog.moc"
1427
#include "moc_qinputdialog.cpp"
1429
#endif // QT_NO_INPUTDIALOG