summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp2
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp33
2 files changed, 23 insertions, 12 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index e62fab6f08..bdfa27282f 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -3793,7 +3793,7 @@ bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) {
Q_Q(QFileDialog);
if (event->matches(QKeySequence::Cancel)) {
- q->hide();
+ q->reject();
return true;
}
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index d48c718d4d..b04711b282 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -130,6 +130,7 @@ private slots:
#endif
void completionOnLevelAfterRoot();
void task233037_selectingDirectory();
+ void task235069_hideOnEscape_data();
void task235069_hideOnEscape();
void task203703_returnProperSeparator();
void task228844_ensurePreviousSorting();
@@ -770,26 +771,36 @@ void tst_QFileDialog2::task233037_selectingDirectory()
current.rmdir("test");
}
+void tst_QFileDialog2::task235069_hideOnEscape_data()
+{
+ QTest::addColumn<QString>("childName");
+ QTest::newRow("listView") << QStringLiteral("listView");
+ QTest::newRow("fileNameEdit") << QStringLiteral("fileNameEdit");
+ QTest::newRow("treeView") << QStringLiteral("treeView");
+}
+
void tst_QFileDialog2::task235069_hideOnEscape()
{
+ QFETCH(QString, childName);
QDir current = QDir::currentPath();
+
QNonNativeFileDialog fd;
+ QSignalSpy spyFinished(&fd, &QDialog::finished);
+ QVERIFY(spyFinished.isValid());
+ QSignalSpy spyRejected(&fd, &QDialog::rejected);
+ QVERIFY(spyRejected.isValid());
fd.setViewMode(QFileDialog::List);
fd.setDirectory(current.absolutePath());
- fd.setAcceptMode( QFileDialog::AcceptSave);
+ fd.setAcceptMode(QFileDialog::AcceptSave);
fd.show();
- QListView *list = fd.findChild<QListView*>("listView");
- list->setFocus();
+ QWidget *child = fd.findChild<QWidget *>(childName);
+ QVERIFY(child);
+ child->setFocus();
QTest::qWait(200);
- QTest::keyClick(list, Qt::Key_Escape);
+ QTest::keyClick(child, Qt::Key_Escape);
QCOMPARE(fd.isVisible(), false);
- QNonNativeFileDialog fd2;
- fd2.setDirectory(current.absolutePath());
- fd2.setAcceptMode( QFileDialog::AcceptSave);
- fd2.show();
- QLineEdit *edit = fd2.findChild<QLineEdit*>("fileNameEdit");
- QTest::keyClick(edit, Qt::Key_Escape);
- QCOMPARE(fd2.isVisible(), false);
+ QCOMPARE(spyFinished.count(), 1); // QTBUG-7690
+ QCOMPARE(spyRejected.count(), 1); // reject(), don't hide()
}
#ifdef QT_BUILD_INTERNAL