Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Detecting press on TreeView
Forum Updated to NodeBB v4.3 + New Features

Detecting press on TreeView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 292 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe McGuchan
    wrote on last edited by Joe McGuchan
    #1

    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 press

    onPressed: {
        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.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Joe McGuchan
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved