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 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)), 'ui', "about.ui") # about_ui = QFile(":/ui/ui/about.ui") uic.loadUi(about_ui, self) self.about_app_logo.setPixmap( QPixmap(os.path.join(os.path.abspath(os.path.dirname(sys.argv)), 'images', 'chevron_logo.png'))) # self.about_app_logo.setPixmap(QPixmap(":/images/images/chevron_logo.png")) self.about_version_value.setText(version) self.about_license_type_value.setText(license_type) self.show()
Then in the main:
def about_dialog(self): about_wizard = AboutDialog(self) # about_wizard.show() pass
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)), "mainwindow.ui") # Type your file path Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) class build(Ui_MainWindow, QtWidgets.QMainWindow): def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) self.setupUi(self) def start(): app = QtWidgets.QApplication(sys.argv) bld = build() bld.show() sys.exit(app.exec_()) if __name__ == '__main__': start()
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):
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!
Finally the solution was:
Into qt Designer:
create a QWidget at the point where HistogramLUTWidget will appear
right click and promote it
set Promoted Class Name: HistogramLUTWidget
set Promoted Class Header: pyqtgraph.widgets.HistogramLUTWidget
- In my code :
self.wu = pg.HistogramLUTWidget(fillHistogram=False)