[PySide] Is dual inheritance clearer?

anatoly techtonik techtonik at gmail.com
Thu Apr 4 07:10:29 CEST 2013


On Thu, Apr 4, 2013 at 8:02 AM, Algis Kabaila <akabaila at pcug.org.au> wrote:

> **
>
> Hi,
>
>
>
> I believe that PySide (and PyQt for that matter) are widely used for GUI
> design. There are two main "orderly" ways to start a GUI program, after
> designing it in the Qt Creator:
>
>
>
> (1)
>
> With dual inheritance:
>
> class MainWindow(QMainWindow, Ui_MainWindow):
>
> def __init__(self, parent=None):
>
> super(MainWindow, self).__init__(parent)
>
> self.setupUi(self)
>
>
>
> (2)
>
> Without dual inheritance:
>
> class MainWindow(QMainWindow):
>
> def __init__(self, parent=None):
>
> super(MainWindow, self).__init__(parent)
>
> self.ui = Ui_MainWindow
>
> self.ui.setupUi(Ui_MainWindow(),self)
>
>
>
> There have been some horror stories about the evils of multiple
> inheritance. What is the preferred method, (1) or (2)?
>

I'd say - that depends on what Ui_MainWindow is, but in general case (2) is
better, because:

 * self.ui defines a namespace to look for methods of UiMW object
 * explicit is better than implicit

-- 
anatoly t.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130404/bcda6f08/attachment.html>


More information about the PySide mailing list