I've been trying to embed a graph into my application using pyqtgraph's PlotWidget. It seemed simple enough while following this tutorial. I have managed to show a graph well enough, the problem is that the graph looks broken. Here is an image of the most simple app I could make to show the problem:
I used the following code:
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()
The steps I followed in Qt Designer were:
When I tried embedding the graph into my program, the same bug appeared. That's why I have made this simple example to showcase it.
Some notes about my setup:
I would appreciate any help with this.
EDIT
The test.ui file contains the following:
<?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>
As @titusjan pointed out, I do have two monitors with different scaling factors. Running the program with the same scaling factors or with just one monitor fixed the problem.
There also are some workarounds in the issue thread @titusjan provided.