Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Detecting checkbox toggle via keyboard on a QTreeWidgetItem
Qt 6.11 is out! See what's new in the release blog

Detecting checkbox toggle via keyboard on a QTreeWidgetItem

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 81 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.
  • 1 Offline
    1 Offline
    1st-alex
    wrote last edited by
    #1

    In my QTreeWidget, each of its QTreeWidgetItems has a checkbox which is set up by calling checklistItem.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable), where checklistItem is a QTreeWidgetItem.

    I can detect whether the user is checking or unchecking the checkbox via mouse click by connecting the itemClicked signal on the QTreeWidget. But how would I do the same if the user toggled the checkbox state by pressing the spacebar on their keyboard? I tried connecting the itemActivated signal, but it doesn't have any effect. The UI I'm building requires that I check for the checkbox state change as soon as it happens, so going through all the checkboxes in the dialog's accept() event handler method is not a viable solution.

    Using Qt for Python 6.11 on macOS 26 Tahoe.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      You should get a https://doc.qt.io/qt-6/qtreewidget.html#itemChanged signal when the data of an item changes.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • 1 1st-alex has marked this topic as solved

      • Login

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