First off, sorry, I am very new to this and as such I know this isn't a well laid out post, but I've been trying to figure out this problem for months (when ever I get the chance to look at the code, so once every month or two).
I'm working with PyQt5, the same issue occurred in PyQt4, and I suspect C++ Qt experience will be very helpful.
I have a number of checkboxes (actually setup as QtPushButtons in a button group), when some of them are clicked other options need to be disabled (not all options are compatible). Works great with mouse clicks BUT the problem is when they are accessed by keyboard shortcuts. Its possible to hit 2 keys at once and both "check" and disable options at the same time (and than you can't uncheck them, see image).
pyQt_checkboxIssue.PNG
In the image attached, you can see that the two observations "Absent" and "Large" are checked (and how can something both be large and absent?! I'm a biologist not a quantum physicist), but everything is now "checkboxItem.setEnables(False)". It seems that the event handler is possibly multi-threaded or something? I didn't have this issue when I made a similar form with HTML/javascript.
Really really simplified version of code:
...
self.
qualityGroup.
buttonClicked[QtWidgets.
QAbstractButton].
connect(self.
setQuality)
def setQuality(self, qualityClicked):
disableIncompatibleObservations(qualityClicked.objectName()) #looks up the option clicked, and sets all incompatible checkboxes/buttons to setEnable(False)
....
...
self.qualityGroup.buttonClicked[QtWidgets.QAbstractButton].connect(self.setQuality)
def setQuality(self, qualityClicked):
disableIncompatibleObservations(qualityClicked.objectName()) #looks up the option clicked, and sets all incompatible checkboxes/buttons to setEnable(False)
....
To copy to clipboard, switch view to plain text mode
Any suggestions how I can disable other checkboxes (or again, in my case, checkable buttons) but do so without any chance of two events conflicting with each other? This system is being designed to record a number of observations quickly from the numpad.
I'm new to PyQt, plus I'm a biologist not a programmer...but I've done a bit of coding in Python, Java, C, C++, VBA, R, HTML/CSS/PHP, etc. So I know enough to get myself in trouble.
Added after 55 minutes:
Quick update, I think the issue is partially resolved by using PyQt5, be adding a quick check to see if the checkbox/button is enabled. Then I can "uncheck" is programmatically and keep going. It is a bit of a workaround, but it works I think... I'm not sure if this just makes it less likely to happen (depending how quickly things happen) or actually solves the problem.
def setQuality(self, qualityClicked):
if not qualityClicked.isEnabled():
qualityClicked.setChecked(False)
print("Attempted to set quality for disabled option")
else:
disableIncompatibleObservations(qualityClicked.objectName()) #looks up the option clicked, and sets all incompatible checkboxes/buttons to setEnable(False)
def setQuality(self, qualityClicked):
if not qualityClicked.isEnabled():
qualityClicked.setChecked(False)
print("Attempted to set quality for disabled option")
else:
disableIncompatibleObservations(qualityClicked.objectName()) #looks up the option clicked, and sets all incompatible checkboxes/buttons to setEnable(False)
To copy to clipboard, switch view to plain text mode
Bookmarks