pyqt5 QWidget 嵌入 pyqtgraph 举例
时间: 2023-12-12 17:04:46 浏览: 117
当然可以嵌入,以下是一个简单的代码示例:
```python
import sys
import pyqtgraph as pg
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt5.QtCore import Qt
class GraphWindow(QWidget):
def __init__(self):
super(GraphWindow, self).__init__()
# Set main window properties
self.setWindowTitle('PyQtGraph Example')
self.setGeometry(100, 100, 640, 480)
self.setWindowFlags(Qt.WindowCloseButtonHint)
# Create a widget for the graph
self.graph_widget = pg.PlotWidget()
# Create some data to plot
x = [1, 2, 3, 4, 5]
y = [1, 0, 3, 2, 4]
# Plot the data
self.plot = self.graph_widget.plot(x, y)
# Add the graph widget to the main window
layout = QVBoxLayout()
layout.addWidget(self.graph_widget)
self.setLayout(layout)
# Create the application and window
app = QApplication(sys.argv)
window = GraphWindow()
window.show()
# Run the application
sys.exit(app.exec_())
```
这是一个简单的 Pyqt5 QWidget 嵌入 pyqtgraph 的示例代码。可以根据需要修改和扩展。
阅读全文