[PyQt] isEnabledTo(0) in PyQt?

FeRD ferdnyc at gmail.com
Fri Jun 22 10:32:34 BST 2018


This feels like a stupid question, and I feel a bit stupid asking it, but
I'm hitting a little difficulty with some PyQt5 code that uses the QWidget
class's isEnabledTo() to make decisions about what to do with a particular
widget.

Specifically, I'm trying to call isEnabledTo(0), which has unique
semantics. (Unlike in Qt4, where it was equivalent to isEnabled().)

As the Qt documentation explains
<http://doc.qt.io/qt-5/qwidget.html#isEnabledTo>:

> isEnabledTo <http://doc.qt.io/qt-5/qwidget.html#enabled-prop>(0) returns
> false if this widget or any if its ancestors was explicitly disabled.
> The word ancestor here means a parent widget within the same window.
> Therefore isEnabledTo <http://doc.qt.io/qt-5/qwidget.html#enabled-prop>(0)
> stops at this widget's window, unlike isEnabled
> <http://doc.qt.io/qt-5/qwidget.html#enabled-prop>() which also takes
> parent windows into considerations.


However, if I wish to ensure that parent windows are ignored by using
isEnabledTo(0) instead of isEnabled(), Python's type checking is working
against me. (isEnabledTo(0) may not strictly be necessary in the following
example, but setting that aside for the moment...)

def someMethod():
        for child in self.findChildren(QDockWidget):
            if child.isFloating() and child.isEnabledTo(0):
                # do something

Python throws up an exception if I pass an int argument into the
isEnabledTo() method:

ERROR Unhandled Exception
Traceback (most recent call last):
  File "somefile.py", line N, in someMethod
    if child.isFloating() and child.isEnabledTo(0):
TypeError: isEnabledTo(self, QWidget): argument 1 has unexpected type 'int'

(The same may be true of isVisibleTo(0) as well, but since that method *is*
documented <http://doc.qt.io/qt-5/qwidget.html#isVisibleTo> as being
identical to isVisible() it's less of a concern.)

Is there something obvious I'm missing here, to achieve the equivalent of
isEnabledTo(0) in PyQt5?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180622/04455384/attachment-0001.html>


More information about the PyQt mailing list