Results 1 to 2 of 2

Thread: simultaneous keypress events and disabling related checkboxes in PyQt5

  1. #1
    Join Date
    Dec 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: simultaneous keypress events and disabling related checkboxes in PyQt5

    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:
    Qt Code:
    1. ...
    2. self.qualityGroup.buttonClicked[QtWidgets.QAbstractButton].connect(self.setQuality)
    3.  
    4. def setQuality(self, qualityClicked):
    5. disableIncompatibleObservations(qualityClicked.objectName()) #looks up the option clicked, and sets all incompatible checkboxes/buttons to setEnable(False)
    6. ....
    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.

    Qt Code:
    1. def setQuality(self, qualityClicked):
    2. if not qualityClicked.isEnabled():
    3. qualityClicked.setChecked(False)
    4. print("Attempted to set quality for disabled option")
    5. else:
    6. 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 
    Last edited by oudent; 5th December 2016 at 21:48.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: simultaneous keypress events and disabling related checkboxes in PyQt5

    Usually events in Qt do not happen at the same time, the event loop always processes one after another.

    From the description it sounds a bit as if the disableIncompatibleObservations() function is missing some consistency checks or does not enable all checkboxes before it starts disabling the incompatible ones.

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 22nd June 2015, 10:30
  2. KeyPress and KeyRelease events not happening as they should
    By hypnotic401 in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2013, 00:49
  3. KeyPress and KeyRelease Events
    By sattu in forum Qt Programming
    Replies: 8
    Last Post: 30th September 2011, 18:23
  4. QT3/QT4 Simultaneous
    By JediSpam in forum Installation and Deployment
    Replies: 8
    Last Post: 24th August 2011, 08:33
  5. Problem with catching keyPress events ?
    By arbi in forum Qt Programming
    Replies: 12
    Last Post: 1st September 2008, 12:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.