correct way of inserting a pyqtgraph histogramLut item from an .ui file.

594 views
Skip to first unread message

pilkrow slash

unread,
Jul 23, 2020, 10:58:15 AM7/23/20
to pyqtgraph
Hello, I have little experience about pyqtgraph and sometimes simple things look difficult.
What I'm looking for is to display a histogramLUT widget into a gui created using qt Designer.
I import the .ui file but I don't know how I can insert it into my code and connect it with an imageItem.

scrnsht1.png

scrnsht0.png



class MainWindow(QMainWindow, ProcessDicom):


uic.loadUi(‘CEtb26.ui’, self)


self.im1 = pg.ImageItem(img,levels=[0, 255])
self.histWindow = self.findChild(PlotWidget, ‘wu’)
self.histWindow.setImageItem(self.im1)


but the only thing I get is an empty plot!


Thank you for your time.


Erik Johansson

unread,
Jul 23, 2020, 12:37:51 PM7/23/20
to pyqt...@googlegroups.com
Hello,

I have done this a few times. To make it work, I use a QWidget for the histogram display which I then promote to a pyqtgraph HistogramLutWidget. Try changing your QGraphics widget to be a QWidget then promote it to a HistogramLUTWidget. I think if you do that the rest should work fine.

Regards,
Erik

--
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/7e99924b-7997-4853-b486-e58c08bbd841o%40googlegroups.com.


Message has been deleted

pilkrow slash

unread,
Jul 23, 2020, 2:31:40 PM7/23/20
to pyqtgraph

pilkrow slash

unread,
Jul 23, 2020, 2:35:30 PM7/23/20
to pyqtgraph
Hello, so I first create a qwidget which I promote to HistogramLUTWidget, right?
In the dialog window I choose the base class name as "QWidget"
the Promoted class name to "HistogramLUTWidget" 
Do I use the pyqtgraph.h as Header File or I have to use another one?
I attached a snapshot of qt designer. 
The qwidget is called wu.

Screenshot from 2020-07-23 21-29-31.png



Finally I have to insert the widget into my  code:
 
uic.loadUi(‘CEtb26.ui’, self)
self.wu = self.findChild(HistogramLUTWidget, 'wu')
self.wu = pg.HistogramLUTWidget(fillHistogram=False)


Is it correct?

Best regards

Τη Πέμπτη, 23 Ιουλίου 2020 - 7:37:51 μ.μ. UTC+3, ο χρήστης Erik J έγραψε:
Hello,

I have done this a few times. To make it work, I use a QWidget for the histogram display which I then promote to a pyqtgraph HistogramLutWidget. Try changing your QGraphics widget to be a QWidget then promote it to a HistogramLUTWidget. I think if you do that the rest should work fine.

Regards,
Erik

On Thu, Jul 23, 2020 at 8:58 AM pilkrow slash <pilkro...@gmail.com> wrote:
Hello, I have little experience about pyqtgraph and sometimes simple things look difficult.
What I'm looking for is to display a histogramLUT widget into a gui created using qt Designer.
I import the .ui file but I don't know how I can insert it into my code and connect it with an imageItem.

scrnsht1.png

scrnsht0.png



class MainWindow(QMainWindow, ProcessDicom):


uic.loadUi(‘CEtb26.ui’, self)


self.im1 = pg.ImageItem(img,levels=[0, 255])
self.histWindow = self.findChild(PlotWidget, ‘wu’)
self.histWindow.setImageItem(self.im1)


but the only thing I get is an empty plot!


Thank you for your time.


--
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.

pilkrow slash

unread,
Jul 23, 2020, 2:38:29 PM7/23/20
to pyqtgraph

screenshot3.png



Τη Πέμπτη, 23 Ιουλίου 2020 - 5:58:15 μ.μ. UTC+3, ο χρήστης pilkrow slash έγραψε:

Erik Johansson

unread,
Jul 23, 2020, 2:57:26 PM7/23/20
to pyqt...@googlegroups.com
So this is where there is a slight disconnect in the way that QtCreator/Designer auto fills the name of the header file. You should use the name of the actual python file without the ".py". In this case that would be "HistogramLUTWidget". Do not use the ".h" suffix. I think QtCreateor/Designer fills that in automatically for a C++ header file.

Hope that helps.
Erik

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/8da5b793-4558-4573-9e09-187ab3e49d4eo%40googlegroups.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
************************************************

pilkrow slash

unread,
Jul 23, 2020, 4:03:58 PM7/23/20
to pyqtgraph
Sorry if there was a display problem with the previous screenshot.
I attach a new one with the recommended changes.
I removed the .h extension

screensht4.png



and I use the same code
        self.wu = self.findChild(HistogramLUTWidget, 'wu')
        self.wu = pg.HistogramLUTWidget(fillHistogram=False)

After I get the error: ModuleNotFoundError: No module named 'histogramlutwidget'

Erik Johansson

unread,
Jul 23, 2020, 4:26:31 PM7/23/20
to pyqt...@googlegroups.com
You have to use the exact name of the python module for the header, without the .py extension. It is case sensitive. You can find the name of the module in the python site packages dir for your distribution. For example on my machine it is here:  /home/erikj/.local/lib/python3.8/site-packages/pyqtgraph/widgets/HistogramLUTWidget.py In this case the header name should be "HistogramLUTWidget". Try that and see if it works.

Regards,
Erik



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/30bc5893-90a1-4425-820a-dc0c84f7f45do%40googlegroups.com.

Erik Johansson

unread,
Jul 23, 2020, 4:51:13 PM7/23/20
to pyqt...@googlegroups.com
If you still get an import error, you might have to try this for the header name: pyqtgraph.widgets.HistogramLUTWidget

That works directly importing from a python terminal session:

>>> import pyqtgraph.widgets.HistogramLUTWidget
>>> 

pilkrow slash

unread,
Jul 23, 2020, 6:35:50 PM7/23/20
to pyqtgraph
Hello, I finally managed to make it work with your help.

sdsds.png



The solution was:
Into qt Designer:
1. create a QWidget at the point where HistogramLUTWidget will appear
2. right click and promote it
3. set Promoted Class Name: HistogramLUTWidget
 set Promoted Class Header:  pyqtgraph.widgets.HistogramLUTWidget
4.save it 
5. In my code I removed the first line of code and left the second one
        #self.wu = self.findChild(HistogramLUTWidget, 'wu') #--> removed
        self.wu = pg.HistogramLUTWidget(fillHistogram=False)
everything worked!

Thank you for your time!

Erik Johansson

unread,
Jul 23, 2020, 6:41:58 PM7/23/20
to pyqt...@googlegroups.com
Glad you got it working!

Regards,
Erik 

--
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.

Jim Crowell

unread,
Jul 24, 2020, 11:31:24 AM7/24/20
to pyqtgraph
Alternatively, you can leave it as a QWidget in designer & add the image & HistorgramLUTItem in code, along the lines of:

Enter code here...    layout = QtGui.QGridLayout()
    widget
.setLayout(layout)
    layout
.setSpacing(0)

    widget
.plotView = pg.GraphicsView()
    layout
.addWidget(widget.plotView, 0, 0, 1, 1)

    widget
.plotItem = pg.PlotItem()
    widget
.plotItem.setAspectLocked()
    widget
.plotItem.resize = widget.resize

   
for axis in ("left", "bottom", "top", "right"):
        widget
.plotItem.showAxis(axis, False)

    widget
.plotView.setCentralItem(widget.plotItem)

    widget
.histogramItem = pg.HistogramLUTItem(image=image_item)

    widget
.plotItem.addItem(widget.histogramItem)




On Thursday, July 23, 2020 at 12:37:51 PM UTC-4, Erik J wrote:
Hello,

I have done this a few times. To make it work, I use a QWidget for the histogram display which I then promote to a pyqtgraph HistogramLutWidget. Try changing your QGraphics widget to be a QWidget then promote it to a HistogramLUTWidget. I think if you do that the rest should work fine.

Regards,
Erik

On Thu, Jul 23, 2020 at 8:58 AM pilkrow slash <pilkro...@gmail.com> wrote:
Hello, I have little experience about pyqtgraph and sometimes simple things look difficult.
What I'm looking for is to display a histogramLUT widget into a gui created using qt Designer.
I import the .ui file but I don't know how I can insert it into my code and connect it with an imageItem.

scrnsht1.png

scrnsht0.png



class MainWindow(QMainWindow, ProcessDicom):


uic.loadUi(‘CEtb26.ui’, self)


self.im1 = pg.ImageItem(img,levels=[0, 255])
self.histWindow = self.findChild(PlotWidget, ‘wu’)
self.histWindow.setImageItem(self.im1)


but the only thing I get is an empty plot!


Thank you for your time.


--
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.
Reply all
Reply to author
Forward
0 new messages