根据列表项的数量创建Qt窗口

2024-09-28 19:26:37 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,这是我的代码:

class Fillscreen(QtGui.QWidget, Ui_View):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent,)
        self.setupUi(self)

    def full(self):
        self.showMaximized()

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)

    monitors = selector.getMonitors()
    resolutions = selector.getResolution(monitors)
    for monitor in monitors:
        window = Fillscreen()
        window.move(monitor[0],monitor[1])
        window.full()
    app.exec_()

monitors看起来像这样: [(-1280, 0, 0, 1024), (0, 0, 1920, 1080), (1920, 0, 3840, 1080)]

它只创建一个窗口,这绝对有意义,因为im在每个循环上覆盖window。 为了解决这个问题,我可以手动创建一个window1window2window3

但是当我不能确定监视器的数量时,我该怎么做呢


Tags: 代码selfappinitdefwindowselectorfull
1条回答
网友
1楼 · 发布于 2024-09-28 19:26:37

使用^{}

...

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    ws = []

    for i in range(QtGui.QApplication.desktop().screenCount()):
        topLeft = QtGui.QApplication.desktop().screenGeometry(i).topLeft()
        window = Fillscreen()
        window.move(topLeft)
        window.full()
        ws.append(window)
    sys.exit(app.exec_())

相关问题 更多 >