[PyQt] When to and not to pass parent argument to widget constructors

rj_pyqt_qwzqfors rj_pyqt_qwzqfors at objectmail.com
Tue Apr 22 15:43:32 BST 2014


I am learning PyQt in order to rewrite my wxPython application to
    use it. Having been accustomed to using wxPython, I am used to being
    required to pass a parent as an argument to the constructor of every
    non-top-level widget. But in PyQt, the parent argument is often
    optional, and I am having some difficulty to know when I should and
    shouldn't use it.

    

    From what I have learned so far, I was guessing that perhaps the
    parent argument should not be used in cases where the parent of the
    widget will later be specified by calling a function (such as
    QDockWidget.setWidget, QMainWindow.addDockWidget,
    QMainWindow.addToolBar, QMainWindow.setCentralWidget,
    QStatusBar.addPermanentWidget, QToolBar.addWidget, ,
    QTabWidget.addTab, etc.), but should be used in all other cases. Is
    this correct? Could someone please help clarify this?

    

    Also, which is the more acceptable practice:

    from PyQt5.QtWidgets import *

    
    OR:

    from PyQt5.QtWidgets import QAction,
      QLabel,...QTabWidget, QToolBar

    
    (I know that generally the use of wild imports is discouraged in
    Python, but it's much easier than having to add a widget to the
    import list whenever I use another one.)

    

    Thank you.

    

    -- Timothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140422/3c4dd076/attachment.html>


More information about the PyQt mailing list