我正在尝试使用自己的级联和平铺定义重载 QWorkspace 类,但是当我尝试使用 .move 函数时,它会相对于子窗口移动内部小部件,而不是相对于工作区移动子窗口。
这是我正在使用的代码:
class MdiArea(QWorkspace):
def tile(self):
if len(self.windowList()) < 2:
return
def cascade(self):
if len(self.windowList()) < 2:
return
windows = []
for window in self.windowList():
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 * 10
y = i * 10
width, height, window = windows[i]
window.move(x, y)
window.raise_()
这是最终对我有用的代码(特别注意'parent()'添加):class MdiArea(QWorkspace):def tile(self):print self.width()if len(self.windowList())< 2:在 self.windowList() 中为窗口返回 i=0: x = i * window.parent().width() y = 5 window.parent().move(x, y) window.parent().raise_ ()
i=i+1
def cascade(self):
if len(self.windowList()) < 2:
return
i=0
for window in self.windowList():
x = i * 15
y = i * 30
window.parent().move(x, y)
window.parent().raise_()
i=i+1