Python QT开发(六)pyside2 窗口全屏显示以及退出处理

1、窗口全屏显示使用

showFullScreen()

举例如下:

if __name__ == "__main__":

    app = QApplication([])

    mainwindow = QWidget()

    #全屏显示
    mainwindow.showFullScreen()
    app.exec_()

2、当窗口全屏之后,我们就需要考虑要怎么推出全屏,这里就需要用keyPressEvent方法了,每一个窗口,都有一个默认的keyPressEvent方法,我们只需要重写这个方法,就可以实现通过键盘推出全屏显示;

举例如下

class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = QWidget()


    #键盘监听事件,当按下ctrl+Z的组合是,关闭窗口
    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Z and event.modifiers() == Qt.ControlModifier:
            self.close()


if __name__ == "__main__":

    app = QApplication([])
    mainwindow = MainWindow()

    #全屏显示
    mainwindow.showFullScreen()
    app.exec_()
原创文章 17 获赞 1 访问量 1499

猜你喜欢

转载自blog.csdn.net/mankaichuang/article/details/105877704