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. Cannot clear selection in GridView/ListView
Forum Updated to NodeBB v4.3 + New Features

Cannot clear selection in GridView/ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 147 Views
  • 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.
  • T Offline
    T Offline
    Tobias Fensch
    wrote on 27 Jan 2025, 13:36 last edited by
    #1

    Hello,

    I want to clear the selection by clicking in the empty space of a GridView or ListView. I am using a a MouseArea that fills the GridView but is underneath the delegate items.

        GridView {
            id: gridViewNodes
            anchors.fill: parent
            cellWidth: root.isSmallLayout ? 108 : 140
            cellHeight: root.isSmallLayout ? 85 : 120
            clip: true
            highlightMoveDuration: 100
            reuseItems: true
    
            // unselect
            Item {
                anchors.fill: parent
                z: -1
    
                TapHandler {
                     // this is never been called
                    onTapped: gridViewNodes.currentIndex = -1
                }
            }
    

    This worked until I port my application to Qt 6.8.1. But now, the event handler is never reached.

    Any suggestions?

    cheers
    Tobias

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tobias Fensch
      wrote on 5 Mar 2025, 12:49 last edited by
      #2

      Qt 6 changed some input event handling, so you might need to adjust the event capturing logic.

      So the solution is:

          GridView {
              id: gridViewNodes
              anchors.fill: parent
              cellWidth: 140
              cellHeight: 120
              clip: true
              highlightMoveDuration: 100
              reuseItems: true
      
              // unselect
              MouseArea {
                  anchors.fill: parent
                  propagateComposedEvents: true
      
                  onClicked: (mouse) => {
                      gridViewNodes.currentIndex = -1
                      nodeListMultiSelectionHandler.resetSelection()
      
                      mouse.accepted = false  // allow selection
                  }
              }
      
      1 Reply Last reply
      0
      • T Tobias Fensch has marked this topic as solved on 5 Mar 2025, 12:49

      • Login

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