QML Image MouseArea onClicked not working
-
I have a QML file, there is an image:
Image { id: iconLocal anchors.right: parent.right source: "images/fake assets/arrow_right_green.png" width: 64; height: 64 opacity: 0.7 MouseArea { anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.LeftButton onClicked: { console.log("Clicked"); } onEntered: { iconLocal.opacity = 1.0; } onExited: { iconLocal.opacity = 0.7; } } }
When the mouse is hovered over the image and moved out I can see that the image opacity is changing, but nothing happens when the image is clicked.
What could explain why the onClicked isn't working?
-
Hellos,
You have mishmash in name of element "iconLabel" vs "iconLocal".
When I fix this code is working - opacity is change when I hover in or out, and when I click by left button console log appear.
I used:import QtQuick 2.7 import QtQuick.Controls 2.0 import QtGraphicalEffects 1.0
-
@poucz said in QML Image MouseArea onClicked not working:
mishmash in name of element "iconLabel" vs "iconLocal".
i guess that is a typo because
@SPlatten said in QML Image MouseArea onClicked not working:
When the mouse is hovered over the image and moved out I can see that the image opacity is changing
...
-
@SPlatten said in QML Image MouseArea onClicked not working:
I've now sorted this out, the issue was caused by using Qt.LeftButton, this has been replaced with Qt.AllButtons and now it works perfectly.
So you were Right-clicking ?
Your code works just fine even with Qt.LeftButton, if you click the left button and there is no other mouseArea overlapping the first one ...