Skip to content

Commit ab1c27d

Browse files
author
Pasi Pentikainen
committed
Clicking on a disabled ListView's delegate breaks mouse interaction
A disabled Flickable should not filter children. This is a backport of change I9f0d8fbfd0922b5c6a9eaffa69212867359f79e0, from Qt5 (later discarded in QtQuick1 restructuring of Qt5). Task-number: QTBUG-20584 Change-Id: Id279907ee90faf19284c12b548467850662a7019 Reviewed-by: Martin Jones <[email protected]> (cherry picked from commit 0f73af9) Reviewed-by: Pasi Pentikäinen <[email protected]>
1 parent fa4dd58 commit ab1c27d

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/declarative/graphicsitems/qdeclarativeflickable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
15821582
bool QDeclarativeFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e)
15831583
{
15841584
Q_D(QDeclarativeFlickable);
1585-
if (!isVisible() || !d->interactive)
1585+
if (!isVisible() || !d->interactive || !isEnabled())
15861586
return QDeclarativeItem::sceneEventFilter(i, e);
15871587
switch (e->type()) {
15881588
case QEvent::GraphicsSceneMousePress:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import QtQuick 1.0
2+
3+
Rectangle {
4+
id: root
5+
width: 100; height: 100
6+
property bool clicked: false
7+
8+
Flickable {
9+
objectName: "flickable"
10+
width: 100; height: 100
11+
contentWidth: column.width; contentHeight: column.height
12+
enabled: false
13+
14+
Column {
15+
id: column
16+
Repeater {
17+
model: 4
18+
Rectangle {
19+
width: 200; height: 300; color: "blue"
20+
MouseArea { anchors.fill: parent; onClicked: { } }
21+
}
22+
}
23+
}
24+
}
25+
26+
MouseArea {
27+
width: 100; height: 30
28+
onClicked: root.clicked = true
29+
}
30+
}

tests/auto/declarative/qdeclarativeflickable/tst_qdeclarativeflickable.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private slots:
7979
void testQtQuick11Attributes_data();
8080
void wheel();
8181
void flickVelocity();
82+
void disabled();
8283

8384
private:
8485
QDeclarativeEngine engine;
@@ -528,6 +529,40 @@ void tst_qdeclarativeflickable::flick(QGraphicsView *canvas, const QPoint &from,
528529
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(to));
529530
}
530531

532+
void tst_qdeclarativeflickable::disabled()
533+
{
534+
QDeclarativeView *canvas = new QDeclarativeView;
535+
canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/disabled.qml"));
536+
canvas->show();
537+
canvas->setFocus();
538+
QVERIFY(canvas->rootObject() != 0);
539+
540+
QDeclarativeFlickable *flick = canvas->rootObject()->findChild<QDeclarativeFlickable*>("flickable");
541+
QVERIFY(flick != 0);
542+
543+
QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50,90)));
544+
545+
QMouseEvent moveEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 80)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
546+
QApplication::sendEvent(canvas, &moveEvent);
547+
548+
moveEvent = QMouseEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 70)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
549+
QApplication::sendEvent(canvas, &moveEvent);
550+
551+
moveEvent = QMouseEvent(QEvent::MouseMove, canvas->mapFromScene(QPoint(50, 60)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
552+
QApplication::sendEvent(canvas, &moveEvent);
553+
554+
QVERIFY(flick->isMoving() == false);
555+
556+
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 60)));
557+
558+
// verify that mouse clicks on other elements still work (QTBUG-20584)
559+
QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 10)));
560+
QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(50, 10)));
561+
562+
QVERIFY(canvas->rootObject()->property("clicked").toBool() == true);
563+
}
564+
565+
531566
template<typename T>
532567
T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName)
533568
{

0 commit comments

Comments
 (0)