【发布时间】:2022-07-11 05:06:24
【问题描述】:
我一直在尝试使用 pyqtgraph 的 PlotWidget 将图表嵌入到我的应用程序中。关注this tutorial 时似乎很简单。我已经设法很好地展示了一个图表,问题是图表看起来已经损坏了。这是我可以用来显示问题的最简单应用程序的图像:
我使用了以下代码:
from PyQt5.QtWidgets import (QMainWindow, QApplication)
from pyqtgraph import PlotWidget
from PyQt5 import uic
import sys
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
# Load the ui file
uic.loadUi("test.ui", self)
self.GraphWidget = self.findChild(PlotWidget,"GraphWidget")
self.GraphWidget.showGrid(x=True, y=True)
# Show The App
self.show()
# Initialize The App
def main():
app = QApplication(sys.argv)
UIWindow = UI()
app.exec_()
if __name__ == '__main__':
main()
我在 Qt Designer 中遵循的步骤是:
- 将 QWidget 添加到主窗口
- 提升为PlotWidget,设置头文件为pyqtgraph
- 保存 test.ui 文件
当我尝试将图表嵌入到我的程序中时,出现了同样的错误。这就是为什么我做了这个简单的例子来展示它。
关于我的设置的一些注意事项:
- 我使用的是 windows 11(可能是这个,但我无法在另一台计算机上测试它)。
- Python 版本 3.9.7
- Qt 版本 5.9.7
- Pyqtgraph 版本 0.11.0
- 我正在使用 Anaconda,为了对此进行测试,我创建了一个干净的环境并只安装了必要的软件包。
我将不胜感激。
编辑
test.ui 文件包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>419</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="PlotWidget" name="GraphWidget" native="true"/>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>PlotWidget</class>
<extends>QWidget</extends>
<header>pyqtgraph</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
【问题讨论】:
-
test.ui 文件中有什么
-
您是否有两台具有不同比例因子的显示器?可能同PyQtGraph issue #756
-
@titusjan 你是绝对正确的!那就是问题所在。非常感谢您发现问题并将我指向另一个线程。
标签: python plot pyqt pyqtgraph