[PyQt] isEnabledTo(0) in PyQt?

J Barchan jnbarchan at gmail.com
Fri Jun 22 10:56:50 BST 2018


On 22 June 2018 at 10:32, FeRD <ferdnyc at gmail.com> wrote:

> 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?
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

​I'm not a PyQt expert, but given that the C++ signature​ is
QWidget::isEnabledTo(const
QWidget *ancestor) have you tried isEnabledTo(None) instead of passing 0 ?


-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180622/e06c13ac/attachment.html>


More information about the PyQt mailing list