qgraphicsview窗口最大化并且按esc退出
时间: 2023-05-26 14:05:36 浏览: 99
As an AI language model, I cannot interact with any window, but here is an idea how you can achieve this in your code using PyQt5:
You can use the `showMaximized` method of the `QGraphicsView` to maximize the window when it is opened, and connect the `keyPressEvent` event of the `QMainWindow` to handle the escape key press and close the window.
Here's a code snippet that demonstrates this:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsView
from PyQt5.QtCore import Qt
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.view = QGraphicsView(self)
self.view.setScene() # set your scene here
self.setCentralWidget(self.view)
self.showMaximized()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.close()
if __name__ == '__main__':
app = QApplication([])
window = MainWindow()
app.exec_()
```