Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qinputdialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qinputdialog.h"
5
6#include "qapplication.h"
7#include "qcombobox.h"
8#include "qdialogbuttonbox.h"
9#include "qlabel.h"
10#include "qlayout.h"
11#include "qlineedit.h"
12#include "qplaintextedit.h"
13#include "qlistview.h"
14#include "qpushbutton.h"
15#include "qspinbox.h"
16#include "qstackedlayout.h"
17#include "qvalidator.h"
18#include "qevent.h"
19#include "qdialog_p.h"
20
21#include <QtCore/qpointer.h>
22
24
32
33static const char *candidateSignal(int which)
34{
35 switch (CandidateSignal(which)) {
36 case TextValueSelectedSignal: return SIGNAL(textValueSelected(QString));
37 case IntValueSelectedSignal: return SIGNAL(intValueSelected(int));
38 case DoubleValueSelectedSignal: return SIGNAL(doubleValueSelected(double));
39
41 break;
42 };
43 Q_UNREACHABLE_RETURN(nullptr);
44}
45
46static const char *signalForMember(const char *member)
47{
48 QByteArray normalizedMember(QMetaObject::normalizedSignature(member));
49
50 for (int i = 0; i < NumCandidateSignals; ++i)
51 if (QMetaObject::checkConnectArgs(candidateSignal(i), normalizedMember))
52 return candidateSignal(i);
53
54 // otherwise, use fit-all accepted signal:
55 return SIGNAL(accepted());
56}
57
59
60/*
61 These internal classes add extra validation to QSpinBox and QDoubleSpinBox by emitting
62 textChanged(bool) after events that may potentially change the visible text. Return or
63 Enter key presses are not propagated if the visible text is invalid. Instead, the visible
64 text is modified to the last valid value.
65*/
67{
69
70public:
72 : QSpinBox(parent) {
74 this, &QInputDialogSpinBox::notifyTextChanged);
76 this, &QInputDialogSpinBox::notifyTextChanged);
77 }
78
80 void textChanged(bool);
81
82private slots:
83 void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
84
85private:
86 void keyPressEvent(QKeyEvent *event) override {
87 if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
88 setProperty("value", property("value"));
89 } else {
91 }
92 notifyTextChanged();
93 }
94
97 notifyTextChanged();
98 }
99};
100
102{
104
105public:
109 this, &QInputDialogDoubleSpinBox::notifyTextChanged);
111 this, &QInputDialogDoubleSpinBox::notifyTextChanged);
112 }
113
114signals:
115 void textChanged(bool);
116
117private slots:
118 void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
119
120private:
121 void keyPressEvent(QKeyEvent *event) override {
122 if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
123 setProperty("value", property("value"));
124 } else {
126 }
127 notifyTextChanged();
128 }
129
132 notifyTextChanged();
133 }
134};
135
137{
138public:
139 QInputDialogListView(QWidget *parent = nullptr) : QListView(parent) {}
141 {
142 if (query == Qt::ImEnabled)
143 return false;
145 }
146};
147
149{
150 Q_DECLARE_PUBLIC(QInputDialog)
151
152public:
154
155 void ensureLayout();
156 void ensureLineEdit();
157 void ensurePlainTextEdit();
158 void ensureComboBox();
159 void ensureListView();
160 void ensureIntSpinBox();
161 void ensureDoubleSpinBox();
165 void setComboBoxText(const QString &text);
166 void setListViewText(const QString &text);
167 QString listViewText() const;
168 void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); }
169 bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; }
170 void textChanged(const QString &text);
172 void currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex);
173
174 mutable QLabel *label;
184 QInputDialog::InputDialogOptions opts;
188};
189
191 : label(nullptr), buttonBox(nullptr), lineEdit(nullptr), plainTextEdit(nullptr), intSpinBox(nullptr), doubleSpinBox(nullptr),
192 comboBox(nullptr), listView(nullptr), inputWidget(nullptr), mainLayout(nullptr)
193{
194}
195
197{
198 Q_Q(QInputDialog);
199
200 if (mainLayout)
201 return;
202
203 if (!inputWidget) {
206 }
207
208 if (!label)
209 label = new QLabel(QInputDialog::tr("Enter a value:"), q);
210#ifndef QT_NO_SHORTCUT
211 label->setBuddy(inputWidget);
212#endif
214
218
219 mainLayout = new QVBoxLayout(q);
224 ensureEnabledConnection(qobject_cast<QAbstractSpinBox *>(inputWidget));
225 inputWidget->show();
226}
227
229{
230 Q_Q(QInputDialog);
231 if (!lineEdit) {
232 lineEdit = new QLineEdit(q);
233#ifndef QT_NO_IM
234 qt_widget_private(lineEdit)->inheritsInputMethodHints = 1;
235#endif
236 lineEdit->hide();
239 }
240}
241
256
272
289
300
311
319
321{
323 if (inputWidget == widget)
324 return;
325
326 if (mainLayout) {
329 inputWidget->hide();
331 widget->show();
332
333 // disconnect old input widget
335 if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(inputWidget))
336 QObject::disconnect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)));
337
338 // connect new input widget and update enabled state of OK button
339 QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(widget);
341 okButton->setEnabled(!spinBox || spinBox->hasAcceptableInput());
342 }
343
345
346 // synchronize the text shown in the new text editor with the current
347 // textValue
348 if (widget == lineEdit) {
350 } else if (widget == plainTextEdit) {
352 } else if (widget == comboBox) {
354 } else if (widget == listView) {
356 ensureLayout();
358 }
359}
360
388
390{
391 int index = comboBox->findText(text);
392 if (index != -1) {
394 } else if (comboBox->isEditable()) {
396 }
397}
398
408
410{
413 return comboBox->itemText(row);
414 } else {
415 return QString();
416 }
417}
418
420{
421 Q_Q(QInputDialog);
422 if (textValue != text) {
423 textValue = text;
424 emit q->textValueChanged(text);
425 }
426}
427
429{
430 Q_Q(QInputDialog);
432 if (textValue != text) {
433 textValue = text;
434 emit q->textValueChanged(text);
435 }
436}
437
439 const QModelIndex & /* oldIndex */)
440{
441 textChanged(comboBox->model()->data(newIndex).toString());
443}
444
492QInputDialog::QInputDialog(QWidget *parent, Qt::WindowFlags flags)
493 : QDialog(*new QInputDialogPrivate, parent, flags)
494{
495}
496
505
517{
518 Q_D(QInputDialog);
519
521
522 /*
523 Warning: Some functions in QInputDialog rely on implementation details
524 of the code below. Look for the comments that accompany the calls to
525 setInputMode() throughout this file before you change the code below.
526 */
527
528 switch (mode) {
529 case IntInput:
530 d->ensureIntSpinBox();
531 widget = d->intSpinBox;
532 break;
533 case DoubleInput:
534 d->ensureDoubleSpinBox();
535 widget = d->doubleSpinBox;
536 break;
537 default:
539 d->chooseRightTextInputWidget();
540 return;
541 }
542
543 d->setInputWidget(widget);
544}
545
547{
548 Q_D(const QInputDialog);
549
550 if (d->inputWidget) {
551 if (d->inputWidget == d->intSpinBox) {
552 return IntInput;
553 } else if (d->inputWidget == d->doubleSpinBox) {
554 return DoubleInput;
555 }
556 }
557
558 return TextInput;
559}
560
569{
570 Q_D(QInputDialog);
571 if (!d->label) {
572 d->label = new QLabel(text, this);
573 } else {
574 d->label->setText(text);
575 }
576}
577
579{
580 Q_D(const QInputDialog);
581 d->ensureLayout();
582 return d->label->text();
583}
584
609{
610 Q_D(QInputDialog);
611 if (!(d->opts & option) != !on)
612 setOptions(d->opts ^ option);
613}
614
622{
623 Q_D(const QInputDialog);
624 return (d->opts & option) != 0;
625}
626
636void QInputDialog::setOptions(InputDialogOptions options)
637{
638 Q_D(QInputDialog);
639
640 InputDialogOptions changed = (options ^ d->opts);
641 if (!changed)
642 return;
643
644 d->opts = options;
645 d->ensureLayout();
646
647 if (changed & NoButtons)
648 d->buttonBox->setVisible(!(options & NoButtons));
649 if ((changed & UseListViewForComboBoxItems) && inputMode() == TextInput)
650 d->chooseRightTextInputWidget();
651 if ((changed & UsePlainTextEditForTextInput) && inputMode() == TextInput)
652 d->chooseRightTextInputWidget();
653}
654
655QInputDialog::InputDialogOptions QInputDialog::options() const
656{
657 Q_D(const QInputDialog);
658 return d->opts;
659}
660
672{
673 Q_D(QInputDialog);
674
676 if (d->inputWidget == d->lineEdit) {
677 d->lineEdit->setText(text);
678 } else if (d->inputWidget == d->plainTextEdit) {
679 d->plainTextEdit->setPlainText(text);
680 } else if (d->inputWidget == d->comboBox) {
681 d->setComboBoxText(text);
682 } else {
683 d->setListViewText(text);
684 }
685}
686
688{
689 Q_D(const QInputDialog);
690 return d->textValue;
691}
692
704{
705 Q_D(QInputDialog);
706 d->ensureLineEdit();
707 d->lineEdit->setEchoMode(mode);
708}
709
711{
712 Q_D(const QInputDialog);
713 if (d->lineEdit) {
714 return d->lineEdit->echoMode();
715 } else {
716 return QLineEdit::Normal;
717 }
718}
719
728{
729 Q_D(QInputDialog);
730 d->ensureComboBox();
731 d->comboBox->setEditable(editable);
732 if (inputMode() == TextInput)
733 d->chooseRightTextInputWidget();
734}
735
737{
738 Q_D(const QInputDialog);
739 if (d->comboBox) {
740 return d->comboBox->isEditable();
741 } else {
742 return false;
743 }
744}
745
754{
755 Q_D(QInputDialog);
756
757 d->ensureComboBox();
758 {
759 const QSignalBlocker blocker(d->comboBox);
760 d->comboBox->clear();
761 d->comboBox->addItems(items);
762 }
763
764 if (inputMode() == TextInput)
765 d->chooseRightTextInputWidget();
766}
767
769{
770 Q_D(const QInputDialog);
772 if (d->comboBox) {
773 const int count = d->comboBox->count();
774 result.reserve(count);
775 for (int i = 0; i < count; ++i)
776 result.append(d->comboBox->itemText(i));
777 }
778 return result;
779}
780
790{
791 Q_D(QInputDialog);
793 d->intSpinBox->setValue(value);
794}
795
797{
798 Q_D(const QInputDialog);
799 if (d->intSpinBox) {
800 return d->intSpinBox->value();
801 } else {
802 return 0;
803 }
804}
805
815{
816 Q_D(QInputDialog);
817 d->ensureIntSpinBox();
818 d->intSpinBox->setMinimum(min);
819}
820
822{
823 Q_D(const QInputDialog);
824 if (d->intSpinBox) {
825 return d->intSpinBox->minimum();
826 } else {
827 return 0;
828 }
829}
830
840{
841 Q_D(QInputDialog);
842 d->ensureIntSpinBox();
843 d->intSpinBox->setMaximum(max);
844}
845
847{
848 Q_D(const QInputDialog);
849 if (d->intSpinBox) {
850 return d->intSpinBox->maximum();
851 } else {
852 return 99;
853 }
854}
855
861void QInputDialog::setIntRange(int min, int max)
862{
863 Q_D(QInputDialog);
864 d->ensureIntSpinBox();
865 d->intSpinBox->setRange(min, max);
866}
867
877{
878 Q_D(QInputDialog);
879 d->ensureIntSpinBox();
880 d->intSpinBox->setSingleStep(step);
881}
882
884{
885 Q_D(const QInputDialog);
886 if (d->intSpinBox) {
887 return d->intSpinBox->singleStep();
888 } else {
889 return 1;
890 }
891}
892
902{
903 Q_D(QInputDialog);
905 d->doubleSpinBox->setValue(value);
906}
907
909{
910 Q_D(const QInputDialog);
911 if (d->doubleSpinBox) {
912 return d->doubleSpinBox->value();
913 } else {
914 return 0.0;
915 }
916}
917
927{
928 Q_D(QInputDialog);
929 d->ensureDoubleSpinBox();
930 d->doubleSpinBox->setMinimum(min);
931}
932
934{
935 Q_D(const QInputDialog);
936 if (d->doubleSpinBox) {
937 return d->doubleSpinBox->minimum();
938 } else {
939 return 0.0;
940 }
941}
942
952{
953 Q_D(QInputDialog);
954 d->ensureDoubleSpinBox();
955 d->doubleSpinBox->setMaximum(max);
956}
957
959{
960 Q_D(const QInputDialog);
961 if (d->doubleSpinBox) {
962 return d->doubleSpinBox->maximum();
963 } else {
964 return 99.99;
965 }
966}
967
973void QInputDialog::setDoubleRange(double min, double max)
974{
975 Q_D(QInputDialog);
976 d->ensureDoubleSpinBox();
977 d->doubleSpinBox->setRange(min, max);
978}
979
990{
991 Q_D(QInputDialog);
992 d->ensureDoubleSpinBox();
993 d->doubleSpinBox->setDecimals(decimals);
994}
995
997{
998 Q_D(const QInputDialog);
999 if (d->doubleSpinBox) {
1000 return d->doubleSpinBox->decimals();
1001 } else {
1002 return 2;
1003 }
1004}
1005
1014{
1015 Q_D(const QInputDialog);
1016 d->ensureLayout();
1017 d->buttonBox->button(QDialogButtonBox::Ok)->setText(text);
1018}
1019
1021{
1022 Q_D(const QInputDialog);
1023 d->ensureLayout();
1024 return d->buttonBox->button(QDialogButtonBox::Ok)->text();
1025}
1026
1034{
1035 Q_D(const QInputDialog);
1036 d->ensureLayout();
1037 d->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
1038}
1039
1041{
1042 Q_D(const QInputDialog);
1043 d->ensureLayout();
1044 return d->buttonBox->button(QDialogButtonBox::Cancel)->text();
1045}
1046
1063void QInputDialog::open(QObject *receiver, const char *member)
1064{
1065 Q_D(QInputDialog);
1066 connect(this, signalForMember(member), receiver, member);
1067 d->receiverToDisconnectOnClose = receiver;
1068 d->memberToDisconnectOnClose = member;
1069 QDialog::open();
1070}
1071
1076{
1077 Q_D(const QInputDialog);
1078 d->ensureLayout();
1079 return QDialog::minimumSizeHint();
1080}
1081
1086{
1087 Q_D(const QInputDialog);
1088 d->ensureLayout();
1089 return QDialog::sizeHint();
1090}
1091
1096{
1097 Q_D(const QInputDialog);
1098 if (visible) {
1099 d->ensureLayout();
1100 d->inputWidget->setFocus();
1101 if (d->inputWidget == d->lineEdit) {
1102 d->lineEdit->selectAll();
1103 } else if (d->inputWidget == d->plainTextEdit) {
1104 d->plainTextEdit->selectAll();
1105 } else if (d->inputWidget == d->intSpinBox) {
1106 d->intSpinBox->selectAll();
1107 } else if (d->inputWidget == d->doubleSpinBox) {
1108 d->doubleSpinBox->selectAll();
1109 }
1110 }
1112}
1113
1122{
1123 Q_D(QInputDialog);
1125 if (result) {
1127 switch (mode) {
1128 case DoubleInput:
1130 break;
1131 case IntInput:
1133 break;
1134 default:
1137 }
1138 }
1139 if (d->receiverToDisconnectOnClose) {
1140 disconnect(this, signalForMember(d->memberToDisconnectOnClose),
1141 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
1142 d->receiverToDisconnectOnClose = nullptr;
1143 }
1144 d->memberToDisconnectOnClose.clear();
1145}
1146
1174 QLineEdit::EchoMode mode, const QString &text, bool *ok,
1175 Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1176{
1177 QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
1180 dialog->setTextValue(text);
1181 dialog->setTextEchoMode(mode);
1183
1184 const int ret = dialog->exec();
1185 if (ok)
1186 *ok = !!ret;
1187 if (ret) {
1188 return dialog->textValue();
1189 } else {
1190 return QString();
1191 }
1192}
1193
1222 const QString &text, bool *ok, Qt::WindowFlags flags,
1223 Qt::InputMethodHints inputMethodHints)
1224{
1225 QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
1229 dialog->setTextValue(text);
1231
1232 const int ret = dialog->exec();
1233 if (ok)
1234 *ok = !!ret;
1235 if (ret) {
1236 return dialog->textValue();
1237 } else {
1238 return QString();
1239 }
1240}
1241
1270 int min, int max, int step, bool *ok, Qt::WindowFlags flags)
1271{
1272 QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
1275 dialog->setIntRange(min, max);
1276 dialog->setIntValue(value);
1277 dialog->setIntStep(step);
1278
1279 const int ret = dialog->exec();
1280 if (ok)
1281 *ok = !!ret;
1282 if (ret) {
1283 return dialog->intValue();
1284 } else {
1285 return value;
1286 }
1287}
1288
1317 double value, double min, double max, int decimals, bool *ok,
1318 Qt::WindowFlags flags, double step)
1319{
1320 QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
1323 dialog->setDoubleDecimals(decimals);
1324 dialog->setDoubleRange(min, max);
1325 dialog->setDoubleValue(value);
1326 dialog->setDoubleStep(step);
1327
1328 const int ret = dialog->exec();
1329 if (ok)
1330 *ok = !!ret;
1331 if (ret) {
1332 return dialog->doubleValue();
1333 } else {
1334 return value;
1335 }
1336}
1337
1368 const QStringList &items, int current, bool editable, bool *ok,
1369 Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
1370{
1371 QString text(items.value(current));
1372
1373 QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
1376 dialog->setComboBoxItems(items);
1377 dialog->setTextValue(text);
1378 dialog->setComboBoxEditable(editable);
1380
1381 const int ret = dialog->exec();
1382 if (ok)
1383 *ok = !!ret;
1384 if (ret) {
1385 return dialog->textValue();
1386 } else {
1387 return text;
1388 }
1389}
1390
1401{
1402 Q_D(QInputDialog);
1403 d->ensureDoubleSpinBox();
1404 d->doubleSpinBox->setSingleStep(step);
1405}
1406
1408{
1409 Q_D(const QInputDialog);
1410 if (d->doubleSpinBox)
1411 return d->doubleSpinBox->singleStep();
1412 else
1413 return 1.0;
1414}
1415
1480
1481#include "qinputdialog.moc"
1482#include "moc_qinputdialog.cpp"
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index.
void setEditTriggers(EditTriggers triggers)
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
\reimp
QItemSelectionModel * selectionModel() const
Returns the current selection model.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
void editingFinished()
This signal is emitted editing is finished.
QLineEdit * lineEdit() const
This function returns a pointer to the line edit of the spin box.
bool hasAcceptableInput() const
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
void insertWidget(int index, QWidget *widget, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Inserts widget at position index, with stretch factor stretch and alignment alignment.
\inmodule QtCore
Definition qbytearray.h:57
The QComboBox widget combines a button with a dropdown list.
Definition qcombobox.h:24
QString itemText(int index) const
Returns the text for the given index in the combobox.
int count
the number of items in the combobox.
Definition qcombobox.h:28
void editTextChanged(const QString &)
This signal is emitted when the text in the combobox's line edit widget is changed.
void currentTextChanged(const QString &)
bool isEditable() const
QString currentText
the current text
Definition qcombobox.h:30
void setEditText(const QString &text)
Sets the text in the combobox's text edit.
QAbstractItemModel * model() const
Returns the model used by the combobox.
int findText(const QString &text, Qt::MatchFlags flags=static_cast< Qt::MatchFlags >(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
Returns the index of the item containing the given text; otherwise returns -1.
Definition qcombobox.h:61
void setCurrentIndex(int index)
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
void accepted()
This signal is emitted when a button inside the button box is clicked, as long as it was defined with...
QPushButton * button(StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or \nullptr if the standard butto...
void rejected()
This signal is emitted when a button inside the button box is clicked, as long as it was defined with...
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
QSize sizeHint() const override
\reimp
Definition qdialog.cpp:959
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition qdialog.cpp:639
virtual int exec()
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition qdialog.cpp:543
QSize minimumSizeHint() const override
\reimp
Definition qdialog.cpp:975
int result() const
In general returns the modal dialog's result code, Accepted or Rejected.
Definition qdialog.cpp:475
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition qdialog.cpp:602
virtual void open()
Definition qdialog.cpp:503
void setVisible(bool visible) override
\reimp
Definition qdialog.cpp:744
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition qdialog.cpp:628
The QDoubleSpinBox class provides a spin box widget that takes doubles.
Definition qspinbox.h:82
void valueChanged(double)
This signal is emitted whenever the spin box's value is changed.
void setLabelText(DialogLabel label, const QString &text)
Sets the text shown in the filedialog in the specified label.
void setOptions(Options options)
void keyPressEvent(QKeyEvent *event) override
\reimp
void mousePressEvent(QMouseEvent *event) override
\reimp
QInputDialogDoubleSpinBox(QWidget *parent=nullptr)
QInputDialogListView(QWidget *parent=nullptr)
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
\reimp
void textChanged(const QString &text)
void ensureLayout() const
void setComboBoxText(const QString &text)
QPointer< QObject > receiverToDisconnectOnClose
QInputDialogListView * listView
void setInputWidget(QWidget *widget)
bool useComboBoxOrListView() const
void ensureEnabledConnection(QAbstractSpinBox *spinBox)
void setListViewText(const QString &text)
QDialogButtonBox * buttonBox
QByteArray memberToDisconnectOnClose
QInputDialog::InputDialogOptions opts
void currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex)
QString listViewText() const
QDoubleSpinBox * doubleSpinBox
QVBoxLayout * mainLayout
QPlainTextEdit * plainTextEdit
void textChanged(bool)
QInputDialogSpinBox(QWidget *parent)
void keyPressEvent(QKeyEvent *event) override
\reimp
void mousePressEvent(QMouseEvent *event) override
\reimp
The QInputDialog class provides a simple convenience dialog to get a single value from the user.
void setDoubleMaximum(double max)
QString cancelButtonText() const
the text for the button used to cancel the dialog
void setTextValue(const QString &text)
int doubleDecimals() const
sets the precision of the double spinbox in decimals
QString okButtonText() const
the text for the button used to accept the entry in the dialog
InputDialogOptions options() const
the various options that affect the look and feel of the dialog
void setDoubleValue(double value)
void intValueChanged(int value)
This signal is emitted whenever the integer value changes in the dialog.
int intValue() const
the current integer value accepted as input
void setDoubleRange(double min, double max)
Sets the range of double precision floating point values accepted by the dialog when used in DoubleIn...
double doubleMaximum() const
the maximum double precision floating point value accepted as input
QSize sizeHint() const override
\reimp
static QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current=0, bool editable=true, bool *ok=nullptr, Qt::WindowFlags flags=Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
Static convenience function to let the user select an item from a string list.
void setCancelButtonText(const QString &text)
double doubleMinimum() const
the minimum double precision floating point value accepted as input
InputMode inputMode() const
the mode used for input
void setIntMaximum(int max)
QInputDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
void setOption(InputDialogOption option, bool on=true)
Sets the given option to be enabled if on is true; otherwise, clears the given option.
void intValueSelected(int value)
This signal is emitted whenever the user selects a integer value by accepting the dialog; for example...
void setIntStep(int step)
void setComboBoxItems(const QStringList &items)
static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode echo=QLineEdit::Normal, const QString &text=QString(), bool *ok=nullptr, Qt::WindowFlags flags=Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
Static convenience function to get a string from the user.
void textValueSelected(const QString &text)
This signal is emitted whenever the user selects a text string by accepting the dialog; for example,...
int intStep() const
the step by which the integer value is increased and decreased
void done(int result) override
Closes the dialog and sets its result code to result.
double doubleValue() const
the current double precision floating point value accepted as input
static QString getMultiLineText(QWidget *parent, const QString &title, const QString &label, const QString &text=QString(), bool *ok=nullptr, Qt::WindowFlags flags=Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
void setTextEchoMode(QLineEdit::EchoMode mode)
QStringList comboBoxItems() const
the items used in the combo box for the input dialog
void doubleValueChanged(double value)
This signal is emitted whenever the double value changes in the dialog.
void setDoubleStep(double step)
void setComboBoxEditable(bool editable)
int intMinimum() const
the minimum integer value accepted as input
double doubleStep() const
the step by which the double value is increased and decreased
void setInputMode(InputMode mode)
bool isComboBoxEditable() const
void setOptions(InputDialogOptions options)
void setIntValue(int value)
void setVisible(bool visible) override
\reimp
void setDoubleDecimals(int decimals)
static int getInt(QWidget *parent, const QString &title, const QString &label, int value=0, int minValue=-2147483647, int maxValue=2147483647, int step=1, bool *ok=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
void setLabelText(const QString &text)
bool testOption(InputDialogOption option) const
Returns true if the given option is enabled; otherwise, returns false.
void setIntRange(int min, int max)
Sets the range of integer values accepted by the dialog when used in IntInput mode,...
QLineEdit::EchoMode textEchoMode() const
the echo mode for the text value
int intMaximum() const
the maximum integer value accepted as input
void doubleValueSelected(double value)
This signal is emitted whenever the user selects a double value by accepting the dialog; for example,...
void setIntMinimum(int min)
void setOkButtonText(const QString &text)
void setDoubleMinimum(double min)
@ UseListViewForComboBoxItems
@ UsePlainTextEditForTextInput
QSize minimumSizeHint() const override
\reimp
virtual void open()
Definition qdialog.cpp:503
QString textValue() const
the text value for the input dialog
static double getDouble(QWidget *parent, const QString &title, const QString &label, double value=0, double minValue=-2147483647, double maxValue=2147483647, int decimals=1, bool *ok=nullptr, Qt::WindowFlags flags=Qt::WindowFlags(), double step=1)
Static convenience function to get a floating point number from the user.
QString labelText() const
the label's text which describes what needs to be input
Q_INVOKABLE QModelIndexList selectedRows(int column=0) const
virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted if the current item changes and its row is different to the row of the previou...
The QKeyEvent class describes a key event.
Definition qevent.h:424
The QLabel widget provides a text or image display.
Definition qlabel.h:20
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition qlayout.cpp:1323
void setSizeConstraint(SizeConstraint)
Definition qlayout.cpp:1241
@ SetMinAndMaxSize
Definition qlayout.h:41
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
void textChanged(const QString &)
This signal is emitted whenever the text changes.
void setText(const QString &)
EchoMode
This enum type describes how a line edit should display its contents.
Definition qlineedit.h:77
The QListView class provides a list or icon view onto a model.
Definition qlistview.h:17
T value(qsizetype i) const
Definition qlist.h:664
\inmodule QtCore
constexpr int row() const noexcept
Returns the row this model index refers to.
\inmodule QtGui
Definition qevent.h:196
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
The QPlainTextEdit class provides a widget that is used to edit and display plain text.
void setLineWrapMode(LineWrapMode mode)
void setPlainText(const QString &text)
Changes the text of the text edit to the string text.
QString toPlainText() const
Returns the text of the text edit as plain text.
void textChanged()
This signal is emitted whenever the document's content changes; for example, when text is inserted or...
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
\inmodule QtCore
Definition qsize.h:25
The QSpinBox class provides a spin box widget.
Definition qspinbox.h:16
void valueChanged(int)
This signal is emitted whenever the spin box's value is changed.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setEnabled(bool)
Definition qwidget.cpp:3358
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9483
void hide()
Hides the widget.
Definition qwidget.cpp:8135
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition qwidget.cpp:9606
void setInputMethodHints(Qt::InputMethodHints hints)
Definition qwidget.cpp:9971
bool visible
whether the widget is visible
Definition qwidget.h:144
QOpenGLWidget * widget
[1]
QString text
Combined button and popup list for selecting options.
InputMethodQuery
@ ImEnabled
@ Horizontal
Definition qnamespace.h:99
@ Key_Return
Definition qnamespace.h:667
@ Key_Enter
Definition qnamespace.h:668
@ UniqueConnection
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static const char * signalForMember(const char *member)
CandidateSignal
@ IntValueSelectedSignal
@ DoubleValueSelectedSignal
@ TextValueSelectedSignal
@ NumCandidateSignals
static const char * candidateSignal(int which)
return ret
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLenum mode
GLuint index
[2]
GLenum GLenum GLsizei count
GLuint GLsizei const GLchar * label
[43]
GLbitfield flags
struct _cl_event * event
GLenum query
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
GLuint GLenum option
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_OBJECT
#define slots
#define signals
#define emit
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
const char property[13]
Definition qwizard.cpp:101
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QObject::connect nullptr
QLineEdit * lineEdit
QListView * listView
QString title
[35]
myObject disconnect()
[26]
QFileDialog dialog(this)
[1]
QList< QTreeWidgetItem * > items
QSpinBox * spinBox
[0]
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
static bool checkConnectArgs(const char *signal, const char *method)
Returns true if the signal and method arguments are compatible; otherwise returns false.