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

时间:2018-06-27 08:40:04

标签: python python-3.x pyqt pyqt4

首先,这是我的代码:

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)]

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

但是当我不确定监视器数量时该怎么办?

1 个答案:

答案 0 :(得分:1)

使用QApplication::desktop()

...

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_())