Detecting press on TreeView
-
I am facing a problem where I would like to detect if a TreeView's flickable is either moving or being pressed. However I am not sure how to do that while still allowing that flickable to work. I suspect this might be connected to a workaround that I used to get the flickable to work properly in the first place.
Below is some toy code that demonstrates the basic problem I am facing:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 1.6 import QtQuick.Controls.Styles 1.4 Window { width: 640 height: 480 visible: true TreeView { id: _treeView anchors.fill: parent TableViewColumn { title: "Name" role: "name" } model: ListModel { id: nameModel ListElement { name: "Alpha" } ListElement { name: "Beta" } ListElement { name: "Carrot" } ListElement { name: "Delta" } ListElement { name: "Epsilon" } } flickableItem.interactive: true style: TreeViewStyle { rowDelegate: Item { height: 128 // Without this mouse area, the tree view will not be flickable. I think this is to // do with grabbing interactions, but I am not totally sure. MouseArea { anchors.fill: parent } } } } // This is the mouse area I would like to add, however adding this means that the treeview will // no longer be Flickable. MouseArea { id: _pressDetector anchors.fill: _treeView propagateComposedEvents: false preventStealing: false } // I want to add the _pressDetector as I would like to be able to display when the treeview is // being pressed OR flicked. Here I have made a little icon that I would like to be yellow in // this case Rectangle { width: 16 height: 16 radius: 16 anchors { right: parent.right bottom: parent.bottom margins: 8 } color: (_treeView.flickableItem.moving || _pressDetector.pressed) ? "yellow" : "red" } // How can I make this indicator yellow when the treeView is being pressed or when it is // moving, while still allowing the user to flick the TreeView? }
Thank you in advance to anyone who is able to help with this problem, it is driving me crazy!
EDIT:
I have tried the following addition to MouseArea, with the hope of registering the pressonPressed: { mouse.accepted = false; // send mouse event to any components }
This works, (the code is ran when the MouseArea is initially pressed, and the flickable is still useable), but my setting accepted to false, we prevent the MouseArea for registering any event when the mouse is released. As we need to register when the MouseArea is being pressed, this is insufficent.
-
Bumping this, I have been working at this issue on and off for a few days now and still cannot find a clear solution. Do I just have to rip up the entirity of TreeView in order to get this to work?