<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 June 2018 at 10:32, FeRD <span dir="ltr"><<a href="mailto:ferdnyc@gmail.com" target="_blank">ferdnyc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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.<br><br>Specifically, I'm trying to call isEnabledTo(0), which has unique semantics. (Unlike in Qt4, where it was equivalent to isEnabled().) <br><br>As <a href="http://doc.qt.io/qt-5/qwidget.html#isEnabledTo" target="_blank">the Qt documentation explains</a>:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><a href="http://doc.qt.io/qt-5/qwidget.html#enabled-prop" style="color:rgb(23,168,26);background-color:rgb(255,255,255);margin:0px;padding:0px;border-color:currentcolor;border-style:none;border-width:0px;font-size:16px;vertical-align:baseline;text-decoration:none" target="_blank">isEnabledTo</a>(0) returns false if this widget or any if its ancestors was explicitly disabled.<br>The word ancestor here means a parent widget within the same window.<br>Therefore <a href="http://doc.qt.io/qt-5/qwidget.html#enabled-prop" style="color:rgb(23,168,26);background-color:rgb(255,255,255);margin:0px;padding:0px;border-color:currentcolor;border-style:none;border-width:0px;font-size:16px;vertical-align:baseline;text-decoration:none" target="_blank">isEnabledTo</a><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">(0)</span> stops at this widget's window, unlike<span> </span><a href="http://doc.qt.io/qt-5/qwidget.html#enabled-prop" style="margin:0px;padding:0px;border-color:currentcolor;border-style:none;border-width:0px;font-size:16px;vertical-align:baseline;color:rgb(23,168,26);text-decoration:none" target="_blank">isEnabled</a>() which also takes parent windows into considerations.</blockquote><br><div>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...)<br><br><font face="monospace, monospace">def someMethod():<br></font><div><font face="monospace, monospace"> for child in self.findChildren(QDockWidget)<wbr>:</font></div><div><font face="monospace, monospace"> if child.isFloating() and child.isEnabledTo(0):</font></div></div><div><font face="monospace, monospace"> # do something<br></font><br>Python throws up an exception if I pass an int argument into the isEnabledTo() method:<br><br><div><font face="monospace, monospace">ERROR Unhandled Exception</font></div><div><font face="monospace, monospace">Traceback (most recent call last):</font></div><div><font face="monospace, monospace"> File "somefile.py", line N, in someMethod</font></div><div><font face="monospace, monospace"> if child.isFloating() and child.isEnabledTo(0):</font></div><div><font face="monospace, monospace">TypeError: isEnabledTo(self, QWidget): argument 1 has unexpected type 'int'</font></div></div><div><br>(The same may be true of isVisibleTo(0) as well, but since that method <u><b>is</b></u> <a href="http://doc.qt.io/qt-5/qwidget.html#isVisibleTo" target="_blank">documented</a> as being identical to isVisible() it's less of a concern.)<br><br>Is there something obvious I'm missing here, to achieve the equivalent of isEnabledTo(0) in PyQt5?</div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a><br></blockquote></div><br><div style="font-family:tahoma,sans-serif" class="gmail_default">I'm not a PyQt expert, but given that the C++ signature is <span style="font-family:monospace,monospace">QWidget::isEnabledTo(const QWidget *ancestor)</span> have you tried <span style="font-family:monospace,monospace">isEnabledTo(None)</span> instead of passing <span style="font-family:monospace,monospace">0</span> ?<br></div><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
</div></div>