Fix ListView.isCurrentItem when used with DelegateModel
Fixes: QTBUG-86744 Pick-to: 5.15 6.1 6.2 Change-Id: I7287b39afc8f84e336aa46739b534e33e4212ea7 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
f75faaf4d2
commit
d9f9d773e9
|
@ -2402,6 +2402,8 @@ void QQuickItemView::createdItem(int index, QObject* object)
|
|||
d->repositionPackageItemAt(item, index);
|
||||
else if (index == d->currentIndex)
|
||||
d->updateCurrent(index);
|
||||
} else if (index == d->currentIndex) {
|
||||
d->updateCurrent(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import QtQuick 2.15
|
||||
import QtQml.Models 2.15
|
||||
|
||||
Item {
|
||||
height: 200
|
||||
width: 100
|
||||
DelegateModel {
|
||||
id: dm
|
||||
model: 2
|
||||
delegate: Item {
|
||||
width: 100; height: 20
|
||||
property bool isCurrent: ListView.isCurrentItem
|
||||
}
|
||||
}
|
||||
ListView {
|
||||
objectName: "listView"
|
||||
model: dm
|
||||
currentIndex: 1
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
|
@ -303,6 +303,7 @@ private slots:
|
|||
void requiredObjectListModel();
|
||||
void clickHeaderAndFooterWhenClip();
|
||||
void animatedDelegate();
|
||||
void isCurrentItem_DelegateModel();
|
||||
|
||||
// WARNING: please add new tests to tst_qquicklistview2; this file is too slow to work with.
|
||||
|
||||
|
@ -10124,6 +10125,20 @@ void tst_QQuickListView::animatedDelegate()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QQuickListView::isCurrentItem_DelegateModel()
|
||||
{
|
||||
QScopedPointer<QQuickView> window(createView());
|
||||
window->setSource(testFileUrl("qtbug86744.qml"));
|
||||
window->resize(640, 480);
|
||||
window->show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
||||
|
||||
QQuickListView* listView = window->rootObject()->findChild<QQuickListView*>("listView");
|
||||
QVERIFY(listView);
|
||||
QVariant value = listView->itemAtIndex(1)->property("isCurrent");
|
||||
QVERIFY(value.toBool() == true);
|
||||
}
|
||||
|
||||
// WARNING: please add new tests to tst_qquicklistview2; this file is too slow to work with.
|
||||
|
||||
QTEST_MAIN(tst_QQuickListView)
|
||||
|
|
Loading…
Reference in New Issue