[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] isEnabledTo(0) in PyQt?
From:       J Barchan <jnbarchan () gmail ! com>
Date:       2018-06-22 9:56:50
Message-ID: CABz3M_9rRhAUz1rRtTRWFXnExspaNRnMkmguxTvuDb=sEQObHg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 22 June 2018 at 10:32, FeRD <ferdnyc@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@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

[Attachment #5 (text/html)]

<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">&lt;<a \
href="mailto:ferdnyc@gmail.com" target="_blank">ferdnyc@gmail.com</a>&gt;</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&#39;m hitting \
a little difficulty with some PyQt5 code that uses the QWidget class&#39;s \
isEnabledTo() to make decisions about what to do with a particular \
widget.<br><br>Specifically, I&#39;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;b \
order-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;b \
order-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&#39;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&#39;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 \
&quot;somefile.py&quot;, 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 \
&#39;int&#39;</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&#39;s less of a concern.)<br><br>Is there \
something obvious I&#39;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&#39;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>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic