Detecting checkbox toggle via keyboard on a QTreeWidgetItem
-
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), wherechecklistItemis a QTreeWidgetItem.I can detect whether the user is checking or unchecking the checkbox via mouse click by connecting the
itemClickedsignal 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 theitemActivatedsignal, 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'saccept()event handler method is not a viable solution.Using Qt for Python 6.11 on macOS 26 Tahoe.
-
You should get a https://doc.qt.io/qt-6/qtreewidget.html#itemChanged signal when the data of an item changes.
-
1 1st-alex has marked this topic as solved