From 83b8d1aef2a840838bbe530794e1dd004e3a22d5 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Fri, 19 Mar 2010 11:41:57 +0100 Subject: clicking on a non focused ItemView would change the cirrent item twice Task-number: QTBUG-8086 Reviewed-by: gabi --- src/gui/itemviews/qabstractitemview.cpp | 2 +- tests/auto/qlistwidget/tst_qlistwidget.cpp | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index dd9a7e6..0f99949 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -2090,7 +2090,7 @@ void QAbstractItemView::focusInEvent(QFocusEvent *event) bool autoScroll = d->autoScroll; d->autoScroll = false; QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index - if (index.isValid() && d->isIndexEnabled(index)) + if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason) selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); d->autoScroll = autoScroll; } diff --git a/tests/auto/qlistwidget/tst_qlistwidget.cpp b/tests/auto/qlistwidget/tst_qlistwidget.cpp index b3f1e1e..eb3fb6b 100644 --- a/tests/auto/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/qlistwidget/tst_qlistwidget.cpp @@ -132,6 +132,7 @@ private slots: void task199503_crashWhenCleared(); void task217070_scrollbarsAdjusted(); void task258949_keypressHangup(); + void QTBUG8086_currentItemChangedOnClick(); protected slots: @@ -1609,5 +1610,35 @@ void tst_QListWidget::task258949_keypressHangup() QCOMPARE(lw.currentIndex(), lw.model()->index(0,0)); } +void tst_QListWidget::QTBUG8086_currentItemChangedOnClick() +{ + qRegisterMetaType("QListWidgetItem*"); + QWidget win; + QHBoxLayout layout(&win); + QListWidget list; + for (int i = 0 ; i < 4; ++i) + new QListWidgetItem(QString::number(i), &list); + + layout.addWidget(&list); + + QLineEdit edit; + layout.addWidget(&edit); + + edit.setFocus(); + win.show(); + + QSignalSpy spy(&list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*))); + + QTest::qWaitForWindowShown(&win); + + QCOMPARE(spy.count(), 0); + + QTest::mouseClick(list.viewport(), Qt::LeftButton, 0, list.visualItemRect(list.item(2)).center()); + + QCOMPARE(spy.count(), 1); + +} + + QTEST_MAIN(tst_QListWidget) #include "tst_qlistwidget.moc" -- cgit v0.12