Pyqtgraph 的 PlotWidget 显示不正确

Pyqtgraph's PlotWidget doesn't show correctly

我一直在尝试使用 pyqtgraph 的 PlotWidget 将图表嵌入到我的应用程序中。跟随 this tutorial 看起来很简单。我已经成功地展示了一张图表,问题是图表看起来很破损。这是我可以用来显示问题的最简单应用程序的图像:

Bugged graph app

我使用了以下代码:

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 中遵循的步骤是:

  1. 添加QWidget到主界面window
  2. 将其提升为PlotWidget,设置头文件为pyqtgraph
  3. 保存test.ui文件

当我尝试将图形嵌入到我的程序中时,出现了同样的错误。这就是为什么我做了这个简单的例子来展示它。

关于我的设置的一些注意事项:

如有任何帮助,我将不胜感激。

编辑

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>

正如@titusjan 所指出的,我确实有两个具有不同比例因子的显示器。 运行具有相同比例因子或只有一台显示器的程序解决了这个问题。

@titusjan 提供的 issue thread 中也有一些解决方法。