Last active
February 1, 2021 02:32
-
-
Save chrismullins/0b9599bee313e52cdc95115af2492fe7 to your computer and use it in GitHub Desktop.
Simple QMainWindow plotting example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindowGUI</class> | |
<widget class="QMainWindow" name="MainWindowGUI"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>800</width> | |
<height>600</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<widget class="QWidget" name="centralwidget"> | |
<layout class="QGridLayout" name="gridLayout"> | |
<item row="0" column="0"> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<widget class="QPushButton" name="pushButton"> | |
<property name="text"> | |
<string>PushButton</string> | |
</property> | |
</widget> | |
</item> | |
<item> | |
<spacer name="horizontalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Horizontal</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>40</width> | |
<height>20</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
</layout> | |
</item> | |
<item row="1" column="0"> | |
<widget class="GraphicsLayoutWidget" name="graphicsView"/> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QMenuBar" name="menubar"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>800</width> | |
<height>20</height> | |
</rect> | |
</property> | |
</widget> | |
<widget class="QStatusBar" name="statusbar"/> | |
<widget class="QToolBar" name="toolBar"> | |
<property name="windowTitle"> | |
<string>toolBar</string> | |
</property> | |
<attribute name="toolBarArea"> | |
<enum>TopToolBarArea</enum> | |
</attribute> | |
<attribute name="toolBarBreak"> | |
<bool>false</bool> | |
</attribute> | |
</widget> | |
</widget> | |
<customwidgets> | |
<customwidget> | |
<class>GraphicsLayoutWidget</class> | |
<extends>QGraphicsView</extends> | |
<header>pyqtgraph</header> | |
</customwidget> | |
</customwidgets> | |
<resources/> | |
<connections/> | |
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5 import QtCore, QtGui, uic | |
import pyqtgraph as pq | |
qtCreatorFile = "MainWindowGUI.ui" # Enter file here. | |
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) | |
class MyApp(QtGui.QMainWindow, Ui_MainWindow): | |
def __init__(self): | |
QtGui.QMainWindow.__init__(self) | |
Ui_MainWindow.__init__(self) | |
self.setupUi(self) | |
self.dataplot = self.graphicsView.addPlot(title="My Data") | |
self.pushButton.clicked.connect(self.btn_clk) | |
def btn_clk(self): | |
L = [1,2,3,4,5] | |
self.dataplot.plot(L) | |
if __name__ == "__main__": | |
app = QtGui.QApplication(sys.argv) | |
window = MyApp() | |
window.show() | |
sys.exit(app.exec_()) |
Hi @phoenixsun2008, sorry about that. I'm not able to reproduce this issue you're having. I just downloaded this gist from 4 years ago and it works exactly as it did then. Can you provide any info about your environment? Here's the output of my pip freeze
numpy==1.20.0
PyQt5==5.15.2
PyQt5-sip==12.8.1
pyqtgraph==0.11.1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi friend, I run the run.py but something wrong like this ---- TypeError: isdeleted() argument 1 must be sip.simplewrapper, not GraphicsLayoutWidget, did you have the same problem? @ @