pyqtgraph...

66 views
Skip to first unread message

David Francis

unread,
Jun 1, 2020, 5:16:19 AM6/1/20
to pyqtgraph
Hi, I am new to programming but have managed to design a GUI interface for my project. I would now like to have a graph on my GUI but when I add one it takes over the whole window... is there a way of imbedding a graph into a text box??

Jerzy Karczmarczuk

unread,
Jun 1, 2020, 6:22:54 AM6/1/20
to pyqt...@googlegroups.com

Le 01/06/2020 à 11:16, David Francis a écrit :

Hi, I am new to programming but have managed to design a GUI interface for my project. I would now like to have a graph on my GUI but when I add one it takes over the whole window... is there a way of imbedding a graph into a text box??

1. A text box is a text box. I wouldn't recommend embedding whatever into it.

2. "takes over the whole window" ?? Did you read the docs concerning PlotWidget etc.?

3. Did you launch pyqtgraph.examples.run(), and thoroughly look the sources? You will see there some embedding examples

4. Google is not your foe!

https://www.learnpyqt.com/courses/qt-creator/embed-pyqtgraph-custom-widgets-qt-app/

https://stackoverflow.com/questions/45872255/embed-a-pyqtgraph-plot-into-a-qt-ui

==

Sorry for being nasty, but if you are a beginner, and instead of doing some work you immediately cry "help!", you will remain a beginner forever.


Jerzy Karczmarczuk
/Caen, France/


Trần Anh

unread,
Jun 1, 2020, 6:27:40 AM6/1/20
to pyqt...@googlegroups.com
Hi David, 
While the guy above me was being mean to you for some unclear reason, he is not all wrong. 

I suggest you should google “Plotting PyQt5” or “PyQt5 and pyqtgraph”. I remember there are a few very nice tutorials out there. The thing you are looking for is to embedded a custom widget to your GUI. That custom widget can be a PlotWidget (which is from pyqtgraph package).

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/3300ca3d-a082-a1d8-14d6-ee22bfde86ee%40gmail.com.
--
Thanks & Regards
Anh Tran

David Francis

unread,
Jun 1, 2020, 12:49:21 PM6/1/20
to pyqtgraph
Hi,

Thanks for the information, I obviously have tried google and been trolling the internet for the last 3 weeks trying to sort this but to no avail....

But thanks for responding to my question

Regards Dave

Erik Johansson

unread,
Jun 1, 2020, 12:55:58 PM6/1/20
to pyqt...@googlegroups.com
Hi David,

I have done a lot of work embedding images, plots and charts into PyQt5 applications. Please describe a bit more what you are trying to accomplish and I'll see if I can get you pointed in the right direction. I'm pretty maxed out with work, so it may be a few days before I get back to you.

Regards,
Erik

On Mon, Jun 1, 2020 at 3:16 AM David Francis <difra...@gmail.com> wrote:
Hi, I am new to programming but have managed to design a GUI interface for my project. I would now like to have a graph on my GUI but when I add one it takes over the whole window... is there a way of imbedding a graph into a text box??

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.


--
************************************************
Erik Johansson
Project Manager, Wavefront Correction System
National Solar Observatory
Daniel K Inouye Solar Telescope
3665 Discovery Drive, Boulder, CO 80303
Tel: 303-735-7723
************************************************

julien....@ensta.fr

unread,
Jun 1, 2020, 1:02:26 PM6/1/20
to pyqtgraph
hi 


If you want i had written a short example using pyQt and pyqtgraph if it could help :




from PyQt5.QtWidgets import QApplication,QVBoxLayout,QHBoxLayout,QWidget,QPushButton,QGridLayout
from PyQt5.QtWidgets import QInputDialog,QSlider,QCheckBox,QLabel,QSizePolicy,QMenu,QMessageBox,QSpinBox
from PyQt5.QtWidgets import QShortcut
from pyqtgraph.Qt import QtCore,QtGui 
from PyQt5.QtCore import Qt
import pyqtgraph as pg 
import sys
import numpy  as np


class WIND(QWidget):
    def __init__(self): # 
        # done  when you start the class 
        super(WIND, self).__init__() # permet d'initialiser la class WIND avec init de la la class Qwidget dont elle depend
        self.setup()
        self.ActionButton()
    
    def setup(self):
        
        self.vbox1=QVBoxLayout() #layout Vertical box 
        self.hbox2=QHBoxLayout()
        
        self.Button1=QPushButton('Bouton 1',self)
        self.Button2=QPushButton('Bouton 2',self)
        
        self.hbox2.addWidget(self.Button1)
        self.hbox2.addWidget(self.Button2)
        
        self.vbox1.addLayout(self.hbox2)
        
        self.Button3=QPushButton('Bouton 3',self)
        self.vbox1.addWidget(self.Button3)
        
        self.grid_layout = QGridLayout() # display with a mesh
        self.checkBox1=QCheckBox('Check box',self)
        self.labelBox2=QLabel('LAbel :',self)
        self.box3=QSpinBox(self)
        self.grid_layout.addWidget(self.checkBox1, 0, 0)
        self.grid_layout.addWidget(self.labelBox2,1,0)
        self.grid_layout.addWidget(self.box3, 0, 1)
    
        self.vbox1.addLayout(self.grid_layout)
        
        hMainLayout=QHBoxLayout()
        hMainLayout.addLayout(self.vbox1)
        
        
        ### add a  2D pyqrgraph 
        
        
        self.winImage = pg.GraphicsLayoutWidget()
        
        self.winImage.setAspectLocked(True)
        self.winImage.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        
        
        self.vbox2=QVBoxLayout()
       
        self.vbox2.addWidget(self.winImage)
        self.vbox2.setContentsMargins(0,0,0,0)
        
        self.p1=self.winImage.addPlot()
        self.imh=pg.ImageItem()
        self.axeX=self.p1.getAxis('bottom')
        self.axeY=self.p1.getAxis('left')
        self.p1.addItem(self.imh)
        self.p1.setMouseEnabled(x=False,y=False)
        self.p1.setContentsMargins(0,0,0,0)
   
        self.p1.setAspectLocked(True,ratio=1)
        self.p1.showAxis('right',show=False)
        self.p1.showAxis('top',show=False)
        self.p1.showAxis('left',show=True)
        self.p1.showAxis('bottom',show=True)
        
        self.data=np.random.rand(350, 400)
        self.imh.setImage(self.data)
        
        hMainLayout.addLayout(self.vbox2)
        
        
        self.setLayout(hMainLayout)  # 
    
    def ActionButton(self): # definition de ce qui se passe quand tu clique
        self.box3.editingFinished.connect(self.Actionbox)
        self.Button1.clicked.connect(self.ActionButton1)
        self.checkBox1.stateChanged.connect(self.ActionCheckBox1)
        
    def Actionbox(self):
        print('box', self.box3.value())
    
    def ActionButton1(self):
        print('action button1')
        
    def ActionCheckBox1(self):
        print('action')
        
if __name__ == "__main__":
    
    appli = QApplication(sys.argv) 
    #appli.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) Si tu veux en noir 
    e = WIND()
    e.show()
    appli.exec_()      


Le lundi 1 juin 2020 18:55:58 UTC+2, Erik J a écrit :
Hi David,

I have done a lot of work embedding images, plots and charts into PyQt5 applications. Please describe a bit more what you are trying to accomplish and I'll see if I can get you pointed in the right direction. I'm pretty maxed out with work, so it may be a few days before I get back to you.

Regards,
Erik

On Mon, Jun 1, 2020 at 3:16 AM David Francis <difra...@gmail.com> wrote:
Hi, I am new to programming but have managed to design a GUI interface for my project. I would now like to have a graph on my GUI but when I add one it takes over the whole window... is there a way of imbedding a graph into a text box??

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqt...@googlegroups.com.

David Francis

unread,
Jun 1, 2020, 2:23:35 PM6/1/20
to pyqtgraph
Hi Erik,

Thanks you for your offer, I am going to have a go myself and see if I can sort it, if not I may give you a shout...

Thanks again

Dave

David Francis

unread,
Jun 1, 2020, 2:26:07 PM6/1/20
to pyqtgraph
Hi Julien,

Thanks for your input I will give it a try.

Many thanks Dave

Jim Crowell

unread,
Jun 2, 2020, 12:48:37 PM6/2/20
to pyqtgraph
Here's a utility function I use to add a plot item to a QWidget, then you can just call widget.plotItem.plot(...)...

def add_plot(widget):
   
"""Add a plot item (that will behave nicely) to a basic QWidget (e.g.
    generated by QTDesigner).

    widget: QWidget

    returns None
    """


    layout
= QtGui.QHBoxLayout()
    widget
.setLayout(layout)
    layout
.setSpacing(0)

    widget
.plotView = pg.GraphicsView()
    layout
.addWidget(widget.plotView)

    widget
.plotItem = pg.PlotItem()
    widget
.plotItem.resize = widget.resize
    widget
.plotView.setCentralItem(widget.plotItem)




Reply all
Reply to author
Forward
0 new messages