Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

C++ QQuickItem with QML MouseArea doesn't behave as expected

$
0
0
Hello, In a C++ QQuickItem derived class, I’m creating a QML Item the following way.     QQmlEngine engine;     QQmlComponent component(&engine);     component.setData("import QtQuick 2.0 \n"                       "Rectangle { "                       "    width:200; "                       "    height:100;"                       "    color : rectMA.containsMouse ? 'red' : 'blue';"                       "    MouseArea { "                       "       id : rectMA;"                       "       anchors.fill: parent;"                       "       drag.target: parent; "                       "       hoverEnabled: true; "                       "       onClicked : console.log('clicked');"                       "    }"                       "}", QUrl());       QQuickItem * item = qobject_cast<QQuickItem *>(component.create());     item->setParentItem(this);     item->setAcceptedMouseButtons(Qt::AllButtons); The MouseArea doesn’t behave as expected: drag is perfectly working onClicked : console.log(‘clicked’); returns nothing color : rectMA.containsMouse ? ‘red’ : ‘blue’;” has no effect. It should when hovered However, the hover is recognized (I don’t explain here why) Using component.loadUrl (QUrl::fromLocalFile("myFile.qml") instead of setData has the same effect (doesn“t work as expected) Of course, if I use this “myFile.qml” as a pure QML without C++, it works Anybody has an Idea ?? Thanks in advance Laurent

Viewing all articles
Browse latest Browse all 4972

Trending Articles