diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2010-10-11 12:28:05 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2010-10-11 12:28:05 (GMT) |
commit | 791ff94dc3b3a01798ce0bf1243de228b3c19e25 (patch) | |
tree | 8138e5363f9e98805ccecb7eac0df7a0a8b9a500 /tests/auto/qlistwidget | |
parent | ae37a39a16c0d28d69fe9e0295ec619d899dc518 (diff) | |
download | Qt-791ff94dc3b3a01798ce0bf1243de228b3c19e25.zip Qt-791ff94dc3b3a01798ce0bf1243de228b3c19e25.tar.gz Qt-791ff94dc3b3a01798ce0bf1243de228b3c19e25.tar.bz2 |
The completer in an itemview would not be activated right away
If you have set the edit triggers to AnyKeyPressed and you press a key
the completer would not kick in because the key event would come before
the lineedit gets focus. The completer is only active when the lineedit
has focus.
Task-number: QTBUG14363
Reviewed-by: ogoffart
Diffstat (limited to 'tests/auto/qlistwidget')
-rw-r--r-- | tests/auto/qlistwidget/tst_qlistwidget.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/qlistwidget/tst_qlistwidget.cpp b/tests/auto/qlistwidget/tst_qlistwidget.cpp index eb3fb6b..8aa50d3 100644 --- a/tests/auto/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/qlistwidget/tst_qlistwidget.cpp @@ -133,6 +133,7 @@ private slots: void task217070_scrollbarsAdjusted(); void task258949_keypressHangup(); void QTBUG8086_currentItemChangedOnClick(); + void QTBUG14363_completerWithAnyKeyPressedEditTriggers(); protected slots: @@ -1640,5 +1641,44 @@ void tst_QListWidget::QTBUG8086_currentItemChangedOnClick() } +class ItemDelegate : public QItemDelegate +{ +public: + ItemDelegate(QObject *parent = 0) : QItemDelegate(parent) + {} + virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const + { + QLineEdit *lineEdit = new QLineEdit(parent); + lineEdit->setFrame(false); + QCompleter *completer = new QCompleter(QStringList() << "completer", lineEdit); + completer->setCompletionMode(QCompleter::InlineCompletion); + lineEdit->setCompleter(completer); + return lineEdit; + } +}; + +void tst_QListWidget::QTBUG14363_completerWithAnyKeyPressedEditTriggers() +{ + QListWidget listWidget; + listWidget.setEditTriggers(QAbstractItemView::AnyKeyPressed); + listWidget.setItemDelegate(new ItemDelegate); + QListWidgetItem *item = new QListWidgetItem(QLatin1String("select an item (don't start editing)"), &listWidget); + item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable); + new QListWidgetItem(QLatin1String("try to type the letter 'c'"), &listWidget); + new QListWidgetItem(QLatin1String("completer"), &listWidget); + listWidget.show(); + listWidget.setCurrentItem(item); + QTest::qWaitForWindowShown(&listWidget); + + QTest::keyClick(listWidget.viewport(), Qt::Key_C); + + QLineEdit *le = qobject_cast<QLineEdit*>(listWidget.itemWidget(item)); + QVERIFY(le); + QCOMPARE(le->text(), QString("completer")); + QCOMPARE(le->completer()->currentCompletion(), QString("completer")); +} + + + QTEST_MAIN(tst_QListWidget) #include "tst_qlistwidget.moc" |