Discussion:
[pyqtgraph] ImageView within GraphicsLayou
Gregory Bättig
2018-09-13 10:03:36 UTC
Permalink
I have a QT application where I use the GraphicsView in combination with
GraphicsLayout. I took the example "GraphicsLayout.py" from the PyQtGraph
repository as a starting point. The below code snippet shows from where I
started out.

app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)

p1 = l.addPlot(title="Plot 1")
p2 = l.addPlot(title="Plot 2")
vb = l.addViewBox(lockAspect=True)
img = pg.ImageItem(np.random.normal(size=(100,100)))
vb.addItem(img)

This approach works fine but I now would like to add an ImageView instead
of an ImageItem to the layout. Mainly because I want to take advantage of
the histogram and slider functionalities already inbuilt in ImageView
objects.

In the example "DataSlicing" they add ImageView objects to a layout, but
there it is a QtGui.QtGridLayout object and the ImageViews are added as
widgets and not as items.

cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView()
imv2 = pg.ImageView()
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)

Is there a way to combine these two approaches, by adding ImageView objects
to a pg.GraphicsLayout, or is that not the right way to go?

Thanks for any kind of advice
--
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/5f47ca47-69dc-40dc-a6f6-de4a37e9517d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick
2018-09-14 04:56:26 UTC
Permalink
Hi,

Yeah, you won't be able to do that as ImageView is a widget and not a
GraphicsItem. You could copy the ImageView code and modify it to do what
you want, but might be overkill. If you just want the histogram and
gradient editor, then something like this would do it:

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np

app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)

p1 = l.addPlot(title="Plot 1")
p2 = l.addPlot(title="Plot 2")
vb = l.addViewBox(lockAspect=True)
img = pg.ImageItem(np.random.normal(size=(100,100)))
vb.addItem(img)
cbar = pg.HistogramLUTItem(image=img)
cbar.gradient.loadPreset('thermal')
l.addItem(cbar)

app.exec_()


If you wanted the timeline/slider too, then you'd need to replicate it as
well, which wouldn't be too hard. Look inside the ImageView code and
copy/paste a bit.

Patrick
Post by Gregory Bättig
I have a QT application where I use the GraphicsView in combination with
GraphicsLayout. I took the example "GraphicsLayout.py" from the PyQtGraph
repository as a starting point. The below code snippet shows from where I
started out.
app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)
p1 = l.addPlot(title="Plot 1")
p2 = l.addPlot(title="Plot 2")
vb = l.addViewBox(lockAspect=True)
img = pg.ImageItem(np.random.normal(size=(100,100)))
vb.addItem(img)
This approach works fine but I now would like to add an ImageView instead
of an ImageItem to the layout. Mainly because I want to take advantage of
the histogram and slider functionalities already inbuilt in ImageView
objects.
In the example "DataSlicing" they add ImageView objects to a layout, but
there it is a QtGui.QtGridLayout object and the ImageViews are added as
widgets and not as items.
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView()
imv2 = pg.ImageView()
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)
Is there a way to combine these two approaches, by adding ImageView
objects to a pg.GraphicsLayout, or is that not the right way to go?
Thanks for any kind of advice
--
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/cf902971-9fba-4cc8-a994-ecbd78d52274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gregory Bättig
2018-09-14 06:47:33 UTC
Permalink
Thanks Patrick! I will try out your proposed solution.
Have a nice weekend!
Post by Patrick
Hi,
Yeah, you won't be able to do that as ImageView is a widget and not a
GraphicsItem. You could copy the ImageView code and modify it to do what
you want, but might be overkill. If you just want the histogram and
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)
p1 = l.addPlot(title="Plot 1")
p2 = l.addPlot(title="Plot 2")
vb = l.addViewBox(lockAspect=True)
img = pg.ImageItem(np.random.normal(size=(100,100)))
vb.addItem(img)
cbar = pg.HistogramLUTItem(image=img)
cbar.gradient.loadPreset('thermal')
l.addItem(cbar)
app.exec_()
If you wanted the timeline/slider too, then you'd need to replicate it as
well, which wouldn't be too hard. Look inside the ImageView code and
copy/paste a bit.
Patrick
Post by Gregory Bättig
I have a QT application where I use the GraphicsView in combination with
GraphicsLayout. I took the example "GraphicsLayout.py" from the PyQtGraph
repository as a starting point. The below code snippet shows from where I
started out.
app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(800,600)
p1 = l.addPlot(title="Plot 1")
p2 = l.addPlot(title="Plot 2")
vb = l.addViewBox(lockAspect=True)
img = pg.ImageItem(np.random.normal(size=(100,100)))
vb.addItem(img)
This approach works fine but I now would like to add an ImageView instead
of an ImageItem to the layout. Mainly because I want to take advantage of
the histogram and slider functionalities already inbuilt in ImageView
objects.
In the example "DataSlicing" they add ImageView objects to a layout, but
there it is a QtGui.QtGridLayout object and the ImageViews are added as
widgets and not as items.
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView()
imv2 = pg.ImageView()
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)
Is there a way to combine these two approaches, by adding ImageView
objects to a pg.GraphicsLayout, or is that not the right way to go?
Thanks for any kind of advice
--
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/c87f5c6e-ee85-4d04-af93-22d4b4ec68a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...