How to display image on the GUI panel created with QGraphicsView using pyqtgraph

1,702 views
Skip to first unread message

aishwarya selvaraj

unread,
Jun 11, 2018, 7:13:00 AM6/11/18
to pyqtgraph
Dear all, 
I have just started to work with PyQt and pyqtgraph.
I have managed to design a GUI for my requirement using Qt designer. I have defined a region on my layout where I want my images to be displayed.
from PyQt5 import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
import random
class Ui_MainWindow(object):
     def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(926, 859)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        
self.Display = QtWidgets.QGraphicsView(self.centralwidget)
        self.Display.setGeometry(QtCore.QRect(30, 130, 461, 541))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.Display.setFont(font)
        self.Display.setMouseTracking(True)
        self.Display.setAutoFillBackground(False)
        self.Display.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.Display.setObjectName("Display")

    def Plot(self):
        // Upon A button click this functionis activated and the image has to be displayed//
        img = np.random.normal(size=(512,512))
        //How to place this images in the region defined??

As mentioned, how do I display the image "img" in the QGraphicsView. 
Can anyone please help me.

Patrick

unread,
Jun 11, 2018, 10:44:17 PM6/11/18
to pyqtgraph
Hi,

If you are making the GUI layout in Qt Designer, you want to "promote" your QGraphicsView to a pyqtplot GraphicsView, following these instructions:

Once you have a pyqtgraph GraphicsView, make an ImageItem and place it inside your GraphicsView. Then self.imageitem.setImage(img) should do it. Check one of the ImageItem examples.

Patrick

aishwarya selvaraj

unread,
Jun 12, 2018, 6:19:06 AM6/12/18
to pyqt...@googlegroups.com
Thank you that helps.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/0496da1f-e040-436d-9d2d-0b7e12175847%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards,
Aishwarya Selvaraj
Reply all
Reply to author
Forward
0 new messages