Problem with MouseArea in delegate
-
Thanks for your answer!
Unfortunately, this did not solve my problem. With an additional MouseArea (as parent of the GridLayout) I can capture the Released-events (form the outer MouseArea), the Pressed-event (from the inner MouseAreas), however I do not see any Entered-events anymore :-(
-
Thanks for your answer!
Unfortunately, this did not solve my problem. With an additional MouseArea (as parent of the GridLayout) I can capture the Released-events (form the outer MouseArea), the Pressed-event (from the inner MouseAreas), however I do not see any Entered-events anymore :-(
I tried your example here - I do not get entered-Events when I move the mouse pointer around while the button is pressed; same problem as in my code.
Once again my scenario - to avoid misunderstandings:
Go to a cell, press the button, keep button pressed, move the pointer to other cells, release the button.
In this case, I would like a pressed-event from the first cell, entered-events from all others, and a released-event from the last one. Seems to be tricky...Cheers
-
Hi!
Here is a complete example (which is unfortunately not doing what I want). Anything wrong here?
import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Layouts 1.1 Window { visible: true color: "black" MouseArea { id: outer anchors.fill: parent onReleased: { console.log("outer - onReleased") } GridLayout { id: fieldGrid anchors.fill:parent rows: 2 columns: 2 Repeater { id: repeater model: myModel Rectangle { id: del Layout.column: col Layout.row: row Layout.fillWidth: true Layout.fillHeight: true Text { anchors.centerIn: parent text: name } MouseArea { id: inner anchors.fill: parent hoverEnabled: true onPressed: { console.log("inner - onPressed") mouse.accepted = false; } onEntered: { console.log("inner - onEntered") } } } } } } ListModel { id: myModel ListElement { row: 0; col: 0; name: "a"} ListElement { row: 0; col: 1; name: "b"} ListElement { row: 1; col: 0; name: "c"} ListElement { row: 1; col: 1; name: "d"} } }
-
Hi!
Here is a complete example (which is unfortunately not doing what I want). Anything wrong here?
import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Layouts 1.1 Window { visible: true color: "black" MouseArea { id: outer anchors.fill: parent onReleased: { console.log("outer - onReleased") } GridLayout { id: fieldGrid anchors.fill:parent rows: 2 columns: 2 Repeater { id: repeater model: myModel Rectangle { id: del Layout.column: col Layout.row: row Layout.fillWidth: true Layout.fillHeight: true Text { anchors.centerIn: parent text: name } MouseArea { id: inner anchors.fill: parent hoverEnabled: true onPressed: { console.log("inner - onPressed") mouse.accepted = false; } onEntered: { console.log("inner - onEntered") } } } } } } ListModel { id: myModel ListElement { row: 0; col: 0; name: "a"} ListElement { row: 0; col: 1; name: "b"} ListElement { row: 1; col: 0; name: "c"} ListElement { row: 1; col: 1; name: "d"} } }
-
I have a simple solution now, using only one MouseArea on top and looking for onPositionChanged. I don't think it is very beautifuly (I have to call childAt() all the time), but at least it is working.
import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Layouts 1.1 Window { visible: true color: "black" GridLayout { id: fieldGrid anchors.fill: parent rows: 2 columns: 2 Repeater { id: repeater model: myModel Rectangle { id: del Layout.column: col Layout.row: row Layout.fillWidth: true Layout.fillHeight: true Text { anchors.centerIn: parent text: name } } } } MouseArea { anchors.fill: parent property point pos: Qt.point(-1, -1) onPressed: { var obj = fieldGrid.childAt(mouse.x, mouse.y) if ( !obj ) return; console.log("onPressed") pos = Qt.point(obj.Layout.row, obj.Layout.column) console.log("newField: " + pos) } onReleased: { console.log("onReleased") } onPositionChanged: { var obj = fieldGrid.childAt(mouse.x, mouse.y) if ( !obj ) return; var newPos = Qt.point(obj.Layout.row, obj.Layout.column) if ( newPos === pos ) return; console.log("newField: " + newPos) pos = newPos; } } ListModel { id: myModel ListElement {row: 0; col: 0; name: "a" } ListElement {row: 0; col: 1; name: "b" } ListElement {row: 1; col: 0; name: "c" } ListElement {row: 1; col: 1; name: "d" } } }
-
I have a simple solution now, using only one MouseArea on top and looking for onPositionChanged. I don't think it is very beautifuly (I have to call childAt() all the time), but at least it is working.
import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Layouts 1.1 Window { visible: true color: "black" GridLayout { id: fieldGrid anchors.fill: parent rows: 2 columns: 2 Repeater { id: repeater model: myModel Rectangle { id: del Layout.column: col Layout.row: row Layout.fillWidth: true Layout.fillHeight: true Text { anchors.centerIn: parent text: name } } } } MouseArea { anchors.fill: parent property point pos: Qt.point(-1, -1) onPressed: { var obj = fieldGrid.childAt(mouse.x, mouse.y) if ( !obj ) return; console.log("onPressed") pos = Qt.point(obj.Layout.row, obj.Layout.column) console.log("newField: " + pos) } onReleased: { console.log("onReleased") } onPositionChanged: { var obj = fieldGrid.childAt(mouse.x, mouse.y) if ( !obj ) return; var newPos = Qt.point(obj.Layout.row, obj.Layout.column) if ( newPos === pos ) return; console.log("newField: " + newPos) pos = newPos; } } ListModel { id: myModel ListElement {row: 0; col: 0; name: "a" } ListElement {row: 0; col: 1; name: "b" } ListElement {row: 1; col: 0; name: "c" } ListElement {row: 1; col: 1; name: "d" } } }