How can I import a pyqtgraph histogram LUT item with .ui

Hello, I’m a bit confused about how I can import into my code a HistogramLUTItem() with the use of an .ui file and not directly.

Can you provide an example of the minimal working example of what your trying to do and what you have done so far?

I have loaded ui files in a dialog like the below but came can be done in main.

class AboutDialog(QDialog):
    def __init__(self, *args, **kwargs):
        super(AboutDialog, self).__init__(*args, **kwargs)
        about_ui = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'ui', "about.ui")
        # about_ui = QFile(":/ui/ui/about.ui")
        uic.loadUi(about_ui, self)
            QPixmap(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'images', 'chevron_logo.png')))
        # self.about_app_logo.setPixmap(QPixmap(":/images/images/chevron_logo.png"))

Then in the main:

def about_dialog(self):
    about_wizard = AboutDialog(self)

Then you can dynamically load the content into from your function into a widget or whatever setup in the UI file. I do this for multiple dialogs and windows in my app. If you can provide more to work with and what you have tried im sure we can give you more specific guidance.

If this for the main window a basic example you can use with a mainwindow.ui file is below.

#!/usr/bin/env python3
# encoding: utf-8
from PyQt5 import uic, QtWidgets
import sys

qtCreatorFile = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "mainwindow.ui")  # Type your file path
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

class build(Ui_MainWindow, QtWidgets.QMainWindow):
    def __init__(self, parent=None):

def start():
    app = QtWidgets.QApplication(sys.argv)
    bld = build()

if __name__ == '__main__':

ok. thank you for your time.

let me make it more clear.

I followed the instructions of this post for including pyqtgraph widgets:

I have created a gui with the help of qt Designer.
I want to include pyqtgraph widgets into my gui.
The inclusion of plot widgets with statistical curves renders ok.
The widgets are included with the use of an external .uic file.
the name of the HistogramLut widget is “wu” and I use it with the function findChild().
My problem is that I don’t know if I’m doing correctly the histogramLUT widget inclusion into the gui. I mean the step of promoting the qwidget to HistogramLUT item.
I include also a snapshot of qtDesigner and also of my gui.

class MainWindow(QMainWindow, ProcessDicom):

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

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

but the only thing I get is an empty plot!



Best regards

Finally 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 it

  1. In my code :

self.wu = pg.HistogramLUTWidget(fillHistogram=False)

everything worked!

1 Like