Is there a signal for "see if any existing QCheckBoxes have changed state"?
-
Hi. I have some checkboxes in a QTable that are created when the user adds more data.
I want to be able to send a signal whenever any of these boxes are checked/unchecked. Is there a signal for this? I know there's a signal for each individual box, but I'm building and destroying the boxes quickly so I don't think I can use this method. I haven't figured out a good alternate way of doing this yet. Please let me know if more information is required. -
Is there a signal for "see if any existing QCheckBoxes have changed state"?
No. There is a signal for each box changing, or you can iterate the boxes comparing them to previously-stored state to see whether any have changed.
but I'm building and destroying the boxes quickly so I don't think I can use this method.
Something wrong here: if the buttons really were destroyed "quickly" there would not be any point having them/the user would not get a chance to interact with them.
There is a QButtonGroup Class for logically grouping buttons like
QCheckBox
es together, but I don't think it would help for your requirement, other than perhaps as a logical starting point. -
if the buttons really were destroyed "quickly" there would not be any point having them/the user would not get a chance to interact with them.
Ok, maybe not that quickly.
Iteration is an option but I am not sure if I wanna have some iterating code going through the checked boxes' state running in the background all the time.
-
@Dummie1138
I really do not understand what you are trying to achieve.-
If you want to run code (immediately) on any (one) checkbox changing state, do it in a slot.
-
For that, connect signal/slot for each checkbox. They can all connect to same slot if desired. If you do not want to connect each checkbox to a slot, you can presumably achieve this alternatively via an
eventFilter
. -
If you want to run code "periodically" to examine current state of multiple checkboxes and compare against state previously saved, do it on e.g. a timer or whenever in your code, iterating the boxes to see their state.
-
-
@Dummie1138 If those checkboxes are just checkable items then model sends a dataChanged signal whenever an item is modified. If you connect to it you can check
roles.contains(Qt::CheckStateRole)
to see if it's the check state that changed.