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

Heads up! You've already completed this tutorial.

I_Stefanis | 2020-07-22 14:03:39 UTC | #1

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.

mike2750 | 2020-07-23 03:13:37 UTC | #2

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(":/forum/images/forum/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__':

I_Stefanis | 2020-07-23 14:20:53 UTC | #3

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') self.histWindow.setImageItem(self.im1)

but the only thing I get is an empty plot!

scrnsht0|661x500 !

scrnsht1|690x454 !

Best regards

I_Stefanis | 2020-07-24 10:55:33 UTC | #4

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!

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

How can I import a pyqtgraph histogram LUT item with .ui was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.