summaryrefslogtreecommitdiffstats
path: root/tests/auto/qcompleter
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-04-03 08:03:56 (GMT)
committerjasplin <qt-info@nokia.com>2009-04-03 08:26:18 (GMT)
commitd684546573785ce40fb5de2b8b3aad88e9958709 (patch)
treed1481ebcdd37080401ba55aaec591fbf15bea747 /tests/auto/qcompleter
parentb2a8a4e0297a7850cf938d85fbfd90cd272d15c2 (diff)
downloadQt-d684546573785ce40fb5de2b8b3aad88e9958709.zip
Qt-d684546573785ce40fb5de2b8b3aad88e9958709.tar.gz
Qt-d684546573785ce40fb5de2b8b3aad88e9958709.tar.bz2
Fix focus policy propagation bug in QCompleter.
Commit 4a00810cc394b7da99ddb2d13eb045352ede25d3 ensures that setting the focus policy of a widget applies to its proxy (if any) as well. This propagation effect is however unfortunate for a QCompleter in PopupCompletion mode. The client widget (typically a QLineEdit or a QTextEdit) acts as the focus proxy to the popup menu. Internally, the completer sets the focus policy of the popup menu to NoFocus, but this should not affect the focus policy of the editor. Reviewed-by: janarve Task-number: 250064
Diffstat (limited to 'tests/auto/qcompleter')
-rw-r--r--tests/auto/qcompleter/tst_qcompleter.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp
index 67b9b67..656995a 100644
--- a/tests/auto/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/qcompleter/tst_qcompleter.cpp
@@ -141,6 +141,7 @@ private slots:
void task178797_activatedOnReturn();
void task189564_omitNonSelectableItems();
void task246056_setCompletionPrefix();
+ void task250064_lostFocus();
private:
void filter();
@@ -1126,5 +1127,62 @@ void tst_QCompleter::task246056_setCompletionPrefix()
QTest::keyPress(comboBox->completer()->popup(), Qt::Key_Enter); // don't crash!
}
+class task250064_TextEdit : public QTextEdit
+{
+public:
+ QCompleter *completer;
+
+ task250064_TextEdit()
+ {
+ completer = new QCompleter;
+ completer->setWidget(this);
+ }
+
+ void keyPressEvent (QKeyEvent *e)
+ {
+ completer->popup();
+ QTextEdit::keyPressEvent(e);
+ }
+};
+
+class task250064_Widget : public QWidget
+{
+ Q_OBJECT
+public:
+ task250064_TextEdit *textEdit;
+
+ task250064_Widget(task250064_TextEdit *textEdit)
+ : textEdit(textEdit)
+ {
+ QTabWidget *tabWidget = new QTabWidget;
+ tabWidget->setFocusPolicy(Qt::ClickFocus);
+ tabWidget->addTab(textEdit, "untitled");
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(tabWidget);
+
+ textEdit->setPlainText("bla bla bla");
+ textEdit->setFocus();
+ }
+
+ void setCompletionModel()
+ {
+ textEdit->completer->setModel(0);
+ }
+};
+
+void tst_QCompleter::task250064_lostFocus()
+{
+ task250064_TextEdit *textEdit = new task250064_TextEdit;
+ task250064_Widget *widget = new task250064_Widget(textEdit);
+ widget->show();
+ QTest::qWait(100);
+ QTest::keyPress(textEdit, 'a');
+ Qt::FocusPolicy origPolicy = textEdit->focusPolicy();
+ QVERIFY(origPolicy != Qt::NoFocus);
+ widget->setCompletionModel();
+ QCOMPARE(textEdit->focusPolicy(), origPolicy);
+}
+
QTEST_MAIN(tst_QCompleter)
#include "tst_qcompleter.moc"