[PyQt] best practices for MDI app

Mark Summerfield list at qtrac.plus.com
Wed Jul 14 10:22:19 BST 2010


On 2010-07-13, Danny Shevitz wrote:
> Howdy,
> 
> I'm a newbie and struggling with developing an MDI app. The basic question
> is this: each of my documents
> 
> looks and acts like a dialog.  When I create my child class, should I
> subclass QDialog or QWidget?
> 
> I am currently using QDialog and add a QDialogButtonBox at the bottom. 
This
> doesn't work as expected.
> 
> When I click close, the MDI child blanks but doesn't disappear. It is as 
if
> the QDialog is closing itself,
> 
> but the MDI page still exists fine. If I subclass QWidget, then do I need
> to reimplement all the button functionality?

QDialog should only be used for dialogs (i.e., top-level windows). Use
QWidget for MDI windows. Or better still use the new MDI classes:
QMdiArea instead of QWorkspace and subclass QMdiSubWindow for the
MDI windows themselves.

Be aware that MDI has been out of fashion for several years so many
people frown upon its use. The fashionable way to do things is to use a
tab widget (which is utterly useless if you want to see two or more
documents at the same time of course) and dock windows. If you need two
or more windows visible and want to be fashionable then you can either
use SDI (multiple top-level main windows -- which duplicate their menus
and toolbars etc. of course) or use splitters.

PS When you "close" a QDialog by default it is hidden not deleted.

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Advanced Qt Programming" - ISBN 0321635906
            http://www.qtrac.eu/aqpbook.html


More information about the PyQt mailing list