[PyQt] Overriding QWidget methods, and/or improving Pythonicity

John Ladasky jladasky at itu.edu
Wed Nov 2 18:29:38 GMT 2016


Hello everyone,

I understand that the PyQt5 package wraps Qt5 in a highly parallel
fashion.  PyQt5's documentation links, function by function, to the Qt
documentation.  Thus we frequently find C++ ways of doing things in our
Python code.

I am currently customizing a QWidget which owns child widgets.  I don't
want ALL my child widgets to be grayed out when I disable the widget.  So I
am overriding the setEnabled() function of my custom widget.  Each child
widget is enabled or disabled separately.

I am always nervous when I override a PyQt class whose code I haven't read
(I'm not much of a C++ programmer, and I don't have the Qt source).  I
don't always know when to call the superclass function because it performs
important housekeeping tasks.  We all know to call the superclass
__init__() within our own __init__().  How about with other methods?  I
always try to get away without a superclass call.  So far I haven't broken
anything.

In any case, setEnabled(True) and setEnabled(False) is starting to bug me.
I have noticed that QWidget lacks enable() and disable().  Is there any
reason that Qt itself does not include methods with these simple names,
which would take no arguments, and are more explicit?  As a Python
programmer, I would prefer to see that.

Of course I could subclass QWidget from Python, to add these features to
any class I design.  But any QWidget subclasses which are already in the Qt
hierarchy would be unaffected.  Monkey patching could work, but I would
prefer a more transparent solution.

Comments are appreciated, thanks.

-- 
*John J. Ladasky Jr., Ph.D.*
*Research Scientist*
*International Technological University*
*2711 N. First St, San Jose, CA 95134 USA*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161102/9ed79a6a/attachment.html>


More information about the PyQt mailing list