42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import pyqtgraph as pg
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QShortcut
|
|
from PyQt5.QtGui import QKeySequence
|
|
|
|
class MyMainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
# 创建一个 PlotWidget
|
|
self.plot_widget = pg.PlotWidget()
|
|
self.plot_widget.plot([1, 2, 3, 4, 5], [1, 2, 3, 4, 5])
|
|
|
|
# 将 PlotWidget 设置为主窗口的中央部件
|
|
self.setCentralWidget(self.plot_widget)
|
|
|
|
# 创建 Ctrl + Q 的快捷键
|
|
shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
|
|
shortcut.activated.connect(self.exitApplication)
|
|
|
|
def exitApplication(self):
|
|
# 在按下 Ctrl + Q 时退出应用程序
|
|
QApplication.quit()
|
|
|
|
def exitApplication():
|
|
# 在按下 Ctrl + Q 时退出应用程序
|
|
QApplication.quit()
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
|
|
# 创建主窗口
|
|
pw = QMainWindow()
|
|
# pw = pg.GraphicsView()
|
|
pw.show()
|
|
shortcut = QShortcut(QKeySequence("Ctrl+Q"), pw)
|
|
shortcut.activated.connect(exitApplication)
|
|
# 显示主窗口
|
|
# main_window.show()
|
|
# 启动 PyQtGraph 事件循环
|
|
app.exec()
|
|
|