[PyQt] FW: cascadeSubWindows oversized

David Boddie david at boddie.org.uk
Tue May 24 00:31:19 BST 2011


On Monday 23 May 2011, Pietro Moras wrote:
> > Can you describe more accurately what you want to see?
> > David
>
> Simply that all “cascaded” child windows be within the Upper Left – Lower
> Right corners of the host MDI Window, with no scroll bar on. - P.M.

I think you will need to write a function to do this, using the QMdiArea's
subWindowList() method to get the subwindows.

There are lots of constraints you could apply to the way windows are
positioned and resized. This cascade() method might do something similar to
what you want, but it's difficult to get the details right without more
information:

class MdiArea(QMdiArea):

    def cascade(self):
    
        if len(self.subWindowList()) < 2:
            return
        
        windows = []
        for window in self.subWindowList():
            windows.append((window.width(), window.height(), window))
        
        windows.sort()
        
        x = 0
        y = 0
        endX = self.width() - min(windows[-1][0], self.width())
        endY = self.height() - min(windows[-1][1], self.height())
        
        for i in range(len(windows)):
        
            x = i * endX/(len(windows) - 1)
            y = i * endY/(len(windows) - 1)
            
            width, height, window = windows[i]
            window.move(x, y)
            window.resize(min(width, self.width() - x),
                          min(height, self.height() - y))
            window.raise_()

David


More information about the PyQt mailing list