isEnabledTo(0) in PyQt?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

isEnabledTo(0) in PyQt?

FeRD
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:
isEnabledTo(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(0) stops at this widget's window, unlike isEnabled() 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 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    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: isEnabledTo(0) in PyQt?

J Barchan


On 22 June 2018 at 10:32, FeRD <[hidden email]> 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:
isEnabledTo(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(0) stops at this widget's window, unlike isEnabled() 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 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    [hidden email]
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

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt